16.12.2012 Views

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

sh<br />

current ERR and EXIT traps, as well as any flags manipulated by EXIT with<br />

the set command; these are restored when the function finishes. The<br />

function ends either by falling off the end of the code of the function body,<br />

or by reaching a return statement. If the function uses typeset to declare<br />

any variables in the function body, the variables are local to the function.<br />

if command then command [elif command then command] ... [else command] fi<br />

In the if statement, if the first (leftmost) command succeeds (returns a zero<br />

exit status), sh runs the command following then. Otherwise, sh runs the<br />

command (if any) following the elif (which is short for “else if”); if that<br />

succeeds, sh runs the command following the next then. If neither case<br />

succeeds, sh runs the command following the else (if any).<br />

select variable [in word ...] do commands done<br />

The select statement can handle menulike interactions with the user. Its<br />

syntax is like the for statement. Each word is printed on the standard error<br />

file, one per line, with an accompanying number. If you omit the “in word ...”<br />

part, sh uses the positional parameters. sh then displays the value of the<br />

variable PS3 to prompt the user to enter a numerical reply. If the reply is an<br />

empty line, sh displays the menu again; otherwise, sh assigns the input line<br />

to the variable REPLY, sets variable to the word selected, and then runs<br />

the commands. sh does this over and over until the loop is ended by an<br />

interrupt, an end-of-file, or an explicit break statement in the commands.<br />

until command1 do command2 done<br />

The until statement runs command1 and tests its exit status for success<br />

(zero) or failure (nonzero). If command1 succeeds, the loop ends;<br />

otherwise, sh runs command2 and then goes back to run and test<br />

command1 again. break and continue commands in the commands can<br />

affect the operation of the loop.<br />

while command1 do command2 done<br />

The while statement works similarly to the until statement. However, the<br />

loop ends whenever command1 is unsuccessful (nonzero exit status).<br />

Shell reserved words are recognized only when they are the unquoted first token of<br />

a command. This lets you pass these reserved words as arguments to commands<br />

run from the shell. The full list of reserved words is:<br />

! done function while<br />

[[ elif if<br />

{ else select<br />

} esac then<br />

case fi time<br />

do for until<br />

<strong>Command</strong> Execution<br />

Before running a simple command,the shell processes the command line,<br />

performing expansion, assignments, and redirection.<br />

First, sh examines the command line and divides it into a series of tokens, which<br />

are either operators or words. An operator is either a control operator, which is<br />

described in “<strong>Command</strong> Syntax” on page 551. Or it can be a redirection operator,<br />

described in “File Descriptors and Redirection” on page 564. A word is any token<br />

that is not an operator.<br />

Next, the shell expands words in the following order:<br />

1. sh performs directory substitution.<br />

556 z/<strong>OS</strong> <strong>V1R9.0</strong> <strong>UNIX</strong> <strong>System</strong> <strong>Services</strong> <strong>Command</strong> Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!