Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script different output when doubleclick vs. run in terminal [closed]

Tags:

bash

I have this script (among others) that generates my wallpaper upon every login/midnight. It has 755 permissions. Part of code:

#/bin/bash

convert -size 1440x900 xc:none wall.png
composite -gravity center ../pics/im256.png wall.png wall.png
composite -geometry 118x67+661+578 ../pics/im-title-white.png wall.png wall.png

TIME=`$HOME/bin/time.py | grep "\."`

if [[ $TIME == *\'* ]]
then
    # <...1...>
else
    # <...2...>
fi

I'm interested if my $TIME variable has ' symbols in it. When there are no ' symbols - everything is good.

Now when I know there is at least one ' symbol (or I can force make that way), when I double-click the script I find myself in else statement, when I run the script in terminal - I find myself in then statement. I would like to always get to then statement, but how?

I cropped the part that is failing (left - correct, right - wrong):

correct imagewrong picture

like image 389
Carl di Ortus Avatar asked Oct 20 '22 20:10

Carl di Ortus


1 Answers

It took me to write a post until I notice that shebang is not actually a shebang. #!/bin/bash fixed the problem.

It appears that incorrect shebang defaulted to /bin/sh which was incapable of running correctly. My login shell is /bin/bash which means running from shell even without bash keyword eg.: ./script.sh defaults to bash and not sh. Why couldn't it do the same on double-click..

like image 94
Carl di Ortus Avatar answered Oct 22 '22 20:10

Carl di Ortus