LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-11-2011, 07:53 PM   #1
wgeorge76
LQ Newbie
 
Registered: May 2011
Posts: 2

Rep: Reputation: 0
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
 
Old 05-11-2011, 08:06 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,357

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
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
 
Old 05-11-2011, 11:49 PM   #3
wgeorge76
LQ Newbie
 
Registered: May 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you for clarifying that for me

I did echo $SHELL and replaced,
Code:
#!/bin/sh
to
Code:
#!/bin/bash
and works.
 
Old 05-12-2011, 01:05 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,357

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
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/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /usr/bin/xterm: Could not exec /bin/bash: Permission Denied suheng Linux - Newbie 2 09-24-2010 05:31 PM
[SOLVED] #!/bin/sh vs #!/bin/bash -- script executes differently; each way = different bugs GrapefruiTgirl Programming 21 12-16-2009 05:30 PM
Really strange problem - RedHat /bin/sh vs /bin/bash leeharris Programming 4 02-13-2009 06:35 AM
How to add paths to sbin, bin/bash, bin sh for users gopi.d Fedora 3 12-07-2007 12:47 AM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM


All times are GMT -5. The time now is 04:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration