The Shebang Line

The shebang line is a magic number, as defined in /usr/share/magica text database of magic numbers for the Linux file command. Magic numbers are used by many different Linux commands to quickly identify a type of file, and the database format is documented in the section five manual page named magic (read by using man 5 magic). For example, magic numbers can be used by the Linux file command to display the identity of a script (no matter what filename is used) as a shell script using a specific shell or other interpreter such as awk or Perl.

You might also find different or new environment variables available to your scripts by using different shells. For example, if you launch csh from the bash command line, you will find several new variables or variables with slightly different definitions, such as

VENDOR=intel MACHTYPE=i386 HOSTTYPE=i3 8 6-linux

On the other hand, bash might provide these variables or variables of the same name with a slightly different definition, such as


Although the behavior of a shebang line is not defined by POSIX, variations of its use can be helpful when you are writing shell scripts. For example, as described in the wish man page, you can use a shell to help execute programs called within a shell script without needing to hard code pathnames of programs. The wish command is a windowing Tool Control Language (tcl) interpreter that can be used to write graphical clients. Avoiding the use of specific pathnames to programs increases shell script portability because not every Unix or Linux system has programs in the same location.

For example, if you want to use the wish command, your first inclination might be to write


Although this will work on many other operating systems, the script will fail under Linux because wish is located under the /usr/bin directory. However, if you write the command line this way,

You can use the wish command (as a binary or a shell script itself); your first inclination might be to write in Linux.

Was this article helpful?

0 0

Post a comment