Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
 var= "$(find . -name 'gen*.bt2')" 


 if [ "$var" == "" ]
    then
         echo bad
    else
         echo great  
 fi

I get errors

./script.sh: line 4: ./gen.4.bt2 ./gen.rev.1.bt2 ./gen.rev.2.bt2 ./gen.1.bt2 ./gen.3.bt2 ./gen.2.bt2: No such file or directory great

However, when I run the same code in terminal, files are listed perfectly, without any error.

Can someone correct me, where am I going wrong?

I need to check, if certain files are present or not, if present then proceed.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The problem is the space in your assignment. The shell is whitespace-sensitive. Your command is the equivalent of:

var="" "./gen.4.bt2 ./gen.rev.1.bt2 ./gen.rev.2.bt2 ./gen.1.bt2 ./gen.3.bt2 ./gen.2.bt2" # output of find

You need to remove the space:

var="$(find . -name 'gen*.bt2')" 
share|improve this answer
    
@ jordanm so silly of me. Bash is real bad when it comes to SPACES. Thanks much!! –  Death Metal Oct 10 '13 at 4:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.