Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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!
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.