How Does Your System Execute Files?

[previous] [next] [table of contents] [index]

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.

[Table of Contents] [Index] [Previous: Using MH from Other Languages] [Next: Shell Command Substitution]


Last change $Date: 1996/06/06 15:14:29 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jerry@ora.com>

Questions or problems regarding this web site should be directed to Steve Gielda.
Copyright 1999 www.cotse.com.  All rights reserved.
Last modified: Friday April 02, 1999.