TechSpot

What does the line: #!/usr/bin/sh do?

By lokem
May 16, 2002
  1. Hi all,

    Hope someone here is familiar with shell scripts...

    Anyway, at the top of a script, there'll almost always be a line like #!/usr/bin/sh

    Anyone know what that line does exactly?

    Does this mean that the script will be called using /usr/bin/sh <scriptname>?

    TIA.
     
  2. Julio Franco

    Julio Franco TechSpot Editor Posts: 6,565   +333

    If I'm not wrong, the location of the language installation files on the server. (the wording might be wrong but you get the idea ;) )
     
  3. lokem

    lokem TS Rookie Topic Starter Posts: 773

    Language installation file? Uhh... DO you mean the shell exec file?
     
  4. recoombe

    recoombe TS Rookie

    i'm no huge expert but usually that line means what shell you have to run the program in to get it to work. when i used to do korn shell programming in junior year of college we always had to put !/bin/sh (or wahtever the syntax is) so that the shell will run the script as korn instead of maybe a c shell script. same thing for perl, etc. if the shell you're trying to execute the program in matches that line then you're ok. its just to make sure that if the shell is different from the language of the program that it runs on the right compiler instead of for example a korn shell script trying to compile on gcc or something like that.
     
  5. Rick

    Rick TechSpot Staff Posts: 6,305   +52 Staff Member


    This is much like to run perl scripts, you have to type in something along the effect of #!/usr/bin/perl

    This line is called a "shebang line".
     
Topic Status:
Not open for further replies.


Add New Comment

TechSpot Members
Login or sign up for free,
it takes about 30 seconds.
You may also...


Get complete access to the TechSpot community. Join thousands of technology enthusiasts that contribute and share knowledge in our forum. Get a private inbox, upload your own photo gallery and more.