Running a shell script
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.scpthe 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.
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 executablecompiles
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 calculateShould you want to use a shell script that updates a variable
in the current environment, run it with the source command. 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/tcshas 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.