LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2010, 01:53 PM   #1
aspn
LQ Newbie
 
Registered: Sep 2010
Location: Bay Area, CA
Distribution: Red Hat
Posts: 2

Rep: Reputation: 0
checking for a file: problem with -e


Please advice why check for presence in the dir could be failing with -e, when file is definitely present, as illustrated in this example (not a real logic, but illustrates my problem):

#!/bin/bash

d=my_dir
for (( i=1; i < 10; i++))
do
j4=`printf "%04d" $i`
f214=$d/s_2_1_${j4}_qseq.txt
if [ ! -e "$f214"* ] ; then
ls -l "$f214"
fi
done

$> -rwxrwxrwx 1 sbsuser domain_users 720258032 Jun 14 11:21 /bruno/RTAOutput/100512_SN101_0440_AFC202J1/Data/Intensities/BaseCalls/s_2_1_0001_qseq.txt

Thanks in advance
 
Old 09-01-2010, 02:36 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Try adding echo "$f214" before the if. Is it what you expect ? Where should the glob be, in your if ?
 
Old 09-01-2010, 02:39 PM   #3
gwalli
LQ Newbie
 
Registered: Jun 2008
Distribution: FC6
Posts: 2
Blog Entries: 1

Rep: Reputation: 0
Not sure what your problem is. I cannot reproduce, but the asterisk
in:
if [ ! -e "$f214"* ]
looks suspicious.
Try:
if [ ! -e "$f214" ]
instead, and see if that helps.

Here is my test script to try to reproduce:
$ cat ~/lq.sh
#!/bin/bash
d=/tmp
echo These files exist:
ls -l ${d}/*qseq.txt*
echo Doing the loop:
for (( i=1; i < 10; i++))
do
f214=$(printf "$d/s_2_1_%04d_qseq.txt" ${i})
[ ! -e "$f214"* ] && ls -l "$f214"
[ -e "$f214" ] && echo ${f214} exists!
done
$ ~/lq.sh
These files exist:
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0001_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0002_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0003_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:32 /tmp/s_2_1_0003_qseq.txt3
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0005_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0006_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0007_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0008_qseq.txt
-rw-rw-r-- 1 walli walli 0 2010-09-01 14:36 /tmp/s_2_1_0009_qseq.txt
Doing the loop:
/tmp/s_2_1_0001_qseq.txt exists!
/tmp/s_2_1_0002_qseq.txt exists!
/home/walli/lq.sh: line 9: [: /tmp/s_2_1_0003_qseq.txt: binary operator expected
/tmp/s_2_1_0003_qseq.txt exists!
ls: cannot access /tmp/s_2_1_0004_qseq.txt: No such file or directory
/tmp/s_2_1_0005_qseq.txt exists!
/tmp/s_2_1_0006_qseq.txt exists!
/tmp/s_2_1_0007_qseq.txt exists!
/tmp/s_2_1_0008_qseq.txt exists!
/tmp/s_2_1_0009_qseq.txt exists!
 
Old 09-02-2010, 11:20 AM   #4
aspn
LQ Newbie
 
Registered: Sep 2010
Location: Bay Area, CA
Distribution: Red Hat
Posts: 2

Original Poster
Rep: Reputation: 0
- solved: extra space

You're right, * is the problem, which I noticed only after copy-paste; extra space in my editor (Notepad++) (ASCII 32) turned into * (42). Weird.
Removing 'star' (extra space) solved the problem.
Thank you guys.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any log file for checking file permission change history in RHEL 5.1? bilalcochin Linux - Newbie 3 04-02-2010 09:57 AM
Checking a file is complete. carlmarshall Linux - Software 3 12-14-2005 09:46 AM
Checking if file exists Haiyadragon Programming 2 04-26-2004 10:07 AM
checking file state in C++ chewysplace Programming 5 02-20-2004 08:27 PM
Checking if a file exists in C? tristan_vdv Programming 3 05-24-2002 10:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration