What does the line '! / Bin / sh -e' do?

At the beginning of the file on my server (linux), which is located in the /etc/init.d/ folder, I have this line:

!/bin/sh -e 

What does this mean, because every time I execute the rest of the script, it works fine, except for an error that shows:

  !/bin/sh not found 

Any ideas?

+9
linux shell
source share
3 answers

Looks like I messed up the shebang line . You need to put "#" before "!".

+9
source share

This line determines which program will execute the given script. For sh usually this line should begin with the # character as follows:

 #!/bin/sh -e 

The long flag name is -e - errexit , which leads to the immediate termination of the script on the first error. A more detailed description from man sh :

If it is not interactive, exit immediately if any untested command fails. The exit status of the command is considered explicitly tested if the command is used to control if , elif , while or until ; or if the command is the left operand && or || operator .

+11
source share
  #!/bin/bash 

this is the first line in the script to tell the system to use the bash shell to execute the script.

+3
source share

All Articles