How Does Your System Execute Files?

You'll need to find out whether your version of UNIX understands the #! notation. This is a way to tell UNIX which interpreter (a shell, Perl, etc.) should read the commands in your file when you execute it (by typing its filename). If your UNIX doesn't recognize #!, you'll need to be sure that you know how to make it read shell scripts using the Bourne shell -- regardless of the shell you use interactively -- because the example shell scripts in this book all use the Bourne shell.

To test your system, let's make a two line file named testing.

NOTE: Do not make programs named test. There's an important system command named test, and your command might be used, accidentally, instead of the system program. Name your test programs testing, atest, whatever -- just not test.

  1. First make the file named testing (use an editor, or just make the file by hand).
  2. Put the following two lines in the file. Be sure to start on the first line of the file, and type this text just as it's shown. Be sure that the hash mark (#) character is at the left-hand edge (column 1) of the first line:
          #! /bin/echo just
          export stuff
          
  3. Exit the editor and save the file. Make the file executable with the chmod +x testing command as you did before.
Now run the program by typing its name at a shell prompt. There are four kinds of responses:
  1. If this happens, then the #! business is working. You'll be able to tell your system which interpreter should read each script:
          % testing
          just testing     (or just ./testing)
          %
          
  2. If this happens, then your UNIX doesn't understand #!, but it ran your program with the Bourne shell anyhow:
          % testing
          %
          
  3. If this happens, then your system ran the program with an older version of the Bourne shell. You should not use comment lines starting with a hash mark (#):
          % testing
          #!: not found
          %
          
  4. If this happens, then your UNIX doesn't understand #!, and it ran your program with the C shell:
          % testing
          export: Command not found.
          %
          
Many UNIX systems, especially newer ones, will answer just testing.

If your system ran the script with the C shell, find a way to make it use the Bourne shell instead. It's best to ask a local expert such as your system administrator.