Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effects of comment (#) lines before and/or after the comment-like #!/bin/sh line

Example one

#!/bin/sh
# purpose: print out current directory name and contents
pwd
ls

Example two

# purpose: print out current directory name and contents
#!/bin/sh
pwd
ls

What is the difference – if I make the first line a comment(#), with #!/bin/sh as the second line, what will happen?

What is meaning of #!/bin/sh ?

like image 411
Manikanta Avatar asked May 13 '13 07:05

Manikanta


People also ask

How does negative comments affect a person?

Frequent criticism, cynical thoughts, and denial can create neural pathways in the brain that encourage sadness. These negative tendencies can cause our brain to distort the truth and make it even more difficult to break the negative cycle.

How negative comments on social media affect you?

Negative comments on social media can only damage your brand's reputation if they go unanswered. Ignoring a negative comment would not only give another reason to the angry client to dislike your brand online but will also damage your social proof.

Why are social media comments important?

Social media comments are a great way to keep a pulse on customer sentiment, both good and bad, and to continue to improve your business and online presence accordingly. So, have a plan, respond to your followers quickly, and watch your community grow even more engaged.


1 Answers

Normally a shell script is run by your default shell defined in the /etc/passwd file. But you can define explicitly a program which can run your script.

Unices uses a common method to determine what program needed to run a specific script (man execve(2)). If the script has the proper execute rights set and in a script the first line starts with a #! characters, it will run by the program defined afterwards.

For example if the first line is #!/usr/bin/awk -f then the rest of the file will be passed to the awk program (so it has to use awk syntax). Or if a Makefile starts with #!/usr/bin/make -f then the rest of the file will be passed to make. You can start the script as a normal program and the script can be written in awk or make (or whatever defined) syntax.

If execve does not find #! as the first two character of the file, it will consider as a normal script file and it will run as it is.

So using #! You can determine the script language and You do not need to know what shell is used by the other user using your script. In any other line #! will be interpretered your default shell, which is usually just a comment line.

like image 96
TrueY Avatar answered Jan 04 '23 04:01

TrueY