LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script #!/bin/sh or #/bin/sh (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-bin-sh-or-bin-sh-880198/)

wgeorge76 05-11-2011 07:53 PM

Bash script #!/bin/sh or #/bin/sh
 
Hello,
This is my first time here, and I normally search the internet for most of my questions about bash scripts, this one looks a bit more serious.

-----

Code:

#!/bin/sh
echo -e '\e[0;34mHello World!'\e[0m'

will@arduino:~$ chmod 755 test

will@arduino:~$ ./test

-e \e[0;34mHello World!\e[0m

-----

changing this 'Hello World!' script above by removing the '!' from #!/bin/sh

-----

Code:

#/bin/sh
echo -e '\e[0;34mHello World!'\e[0m'

will@arduino:~$ chmod 755 test

will@arduino:~$ ./test

Hello World!

-----

the Hello World! above is in blue.

It may not be as serious, but without the '!' the script echo commands work but is in one color when I am editing it with nano. With the '!' the echo commands fail, but it has the coloring while editing with nano.

Thank you

chrism01 05-11-2011 08:06 PM

That'll be 2 different issues.

1. If a shell file starts with
Code:

#!/dir/some_shell
then

Code:

./file.sh
will run the file using the shell invocation specified.
If the 1st line does not start with '#!', but
Code:

#/dir/some_shell
then it that line is treated as a normal comment and ignored and the default shell you are logged in with will be used. (echo $SHELL).
IOW '#!' at the start of the 1st line is a special signal to the system to treat the remaining chars as the program to use; this also works for perl amongst others.

2. nano; I'm guessing there's a nano cfg somewhere that uses similar rules to try to understand/highlight the syntax of the file.


Personally I use vim, which does syntax highlighting for file types it recognises.

HTH

wgeorge76 05-11-2011 11:49 PM

Thank you for clarifying that for me

I did echo $SHELL and replaced,
Code:

#!/bin/sh
to
Code:

#!/bin/bash
and works.

chrism01 05-12-2011 01:05 AM

I recommend these
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/


All times are GMT -5. The time now is 07:52 PM.