Archive - Originally posted on "The Horse's Mouth" - 2005-05-29 10:44:45 - Graham Ellis
If you write a program in Perl, your colleague writes a program in Tcl/Tk and your company runs an open source program that's written in Python, how do your users ensure that they get the right interpretter to run the program? You certainly don't want them to have to remember to type something like:
perl bestest
tcl greatprog
python goodprice
On systems running a Microsoft Windows operating system, you can simply give the programs appropriate extensions - .pl for Perl, .tcl for Tcl and .py for Python in my examples and - provided that the registry is set up correctly - the operating system will know which language interpretter to use.
On systems running Linux or Unix based operating systems, you have two steps to take:
a) The very first line of the file should start # - ! - then the full path to the executable language - typically:
#!/usr/bin/perl
#!/usr/bin/tclsh or #!/usr/bin/wish
#!/usr/bin/python
b) The file should be marked as being executable - normally done using the chmod command. Examples:
chmod ug+x bestest
chmod a+x greatprog
chmod 550 goodprice
On all systems you might also want to update the path that the operating system looks in for executable files using the PATH environment variable. Setting of this variable depends on which (if any) command line interpretter you're using. If you don't set the path, you can still run the program by double clicking it (windows explorer) or prefixing the file name with ./ to run it on Unix or Linux. Thus:
./bestest
./greatprog
./goodprice