2
 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.

1 Answer 1

3

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')" 
1
  • @ jordanm so silly of me. Bash is real bad when it comes to SPACES. Thanks much!! Oct 10, 2013 at 4:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .