z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Running a shell script

z/OS UNIX System Services User's Guide
SA23-2279-00

You can run a shell script by typing the name of the file that contains the script. For example, suppose you have a script named totals.scp that has three shell commands in it. If you enter:
totals.scp
the shell runs the three commands.

Before you can run a shell script, you must have read and execute permission to the file. Use the chmod and umask commands to set the permissions. See the discussion of permissions in Handling security for your files. See the descriptions of chmod and umask in z/OS UNIX System Services Command Reference.

For another example, suppose you want to compile a collection of files written in the C programming language. You could use the c89, cc, or c++ command. The c89 command, for example, compiles any file file.c, link-edits the object module, and produces an executable file. The shell script:
c89 -c file1.c file2.c                         # compile only
c89 -o outfile file1.o file2.o file3.c         # outfile for executable
compiles and link-edits the files and produces an executable file, outfile. Notice that in a shell script you precede a comment with a #.

If you store this script in an executable file named compile, it could be run with the single command compile. A new process is created for the script to run in.

To run a shell script in your current environment, without creating a new process, use the source command. You could run the calculate shell script this way:
source calculate
Should you want to use a shell script that updates a variable in the current environment, run it with the source command.
Tip: To improve shell script performance, set the _BPX_SPAWN_SCRIPT environment variable to NO when using the tcsh shell. This variable is intended only for use with the z/OS® shell. If this variable is inherited from a z/OS shell session, put
#!/bin/tcsh
as the first line in your tcsh shell scripts to avoid any errors. If tcsh is your login shell, you should unset _BPX_SPAWN_SCRIPT, because it is only used for increasing performance of z/OS shell scripts.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014