Qshell executes commands of several types: regular and special built-in utilities, reserved words, aliases, functions, and external files. These commands may be used alone or combined into compound commands.
Each command runs in a process, which is similar to an iSeries
job. Some commands run in the current process, while others run in
child processes under the shell that spawned them. Child processes
do not automatically receive the values of the
To find a command, Qshell searches the directories listed in the
PATH environment variable. The current directory is not searched
unless it is listed in the
There are several ways to run a command: in background mode,
through command substitution, in the current process under the
source utility, through the
xargs
utility, and through the
Before executing a command, Qshell substitutes values for
certain tokens through the process of word expansion. The
eval
utility causes Qshell to make two substitution
A Qshell function, like a Qshell script, is a
Qshell functions are similar to subroutines, functions, and
procedures in other languages, and therefore can be used to
implement modularity in Qshell scripts. While functions are usually
defined in scripts or profile files, at times it is useful to type
a function into an interactive session to help automate ad hoc
repetitive
One of the most important things to understand about functions
is that they execute in the caller's process. Qshell begins a new
process when it runs a script or external utility, but it does not
start a new process when it executes a function. This means that
functions are more efficient than scripts, and that a function can
change its caller's
There are two acceptable ways to define a function. The older way, taken from the Bourne shell, works on all releases of Qshell. Here is the syntax:
function-name
() {
commands
}
The function name is followed by empty parentheses, which serve no purpose except to tell Qshell that a function is being defined. Next is an
The
function
function-name
{
commands
}
This syntax
A function must be defined before it can be invoked. For this reason, it is customary to place function definitions at the beginning of scripts.
In Figure 13.1, the
|
|
function lcname { echo tr '[:upper:]' '[:lower:]' ; }
/home/jsmith $
filename=/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYMBR.MBR
/home/jsmith $
lcname $filename
/qsys.lib/mylib.lib/myfile.file/mymbr.mbr
|
|
Here is the same function defined with the older syntax:
lcname() { echo tr '[:upper:]' '[:lower:]' ; }