Monday, September 26, 2011

What should be shebang/hashbang line for shell scripts to run irrespective of environment?

It is common to need to edit the shebang line after copying a script from one computer to another because the path that was coded into the script may not apply on a new machine, depending on the consistency in past convention of placement of the interpreter. For this and other reasons, the program /usr/bin/env can be used to circumvent this limitation by introducing a level of indirection. “#!” is followed by /usr/bin/env, followed by the desired command without full path as below:

#!/usr/bin/env sh or #!/usr/bin/env perl

No comments :