manpages.info - online man pages   

SunOS man pages : until (1)

User Commands                                            while(1)

NAME

while, until - shell built-in functions to repetitively exe- cute a set of actions while/until conditions are evaluated TRUE

SYNOPSIS

sh while [ conditions ] ; do actions ; done until [ conditions ] ; do actions ; done csh while ( conditions ) [ ... ] # do actions end ksh while [ conditions ] ; do actions ; done until [ conditions ] ; do actions ; done

DESCRIPTION

sh A while command repeatedly executes the while conditions and, if the exit status of the last command in the condi- tions list is 0, executes the do actions; otherwise the loop terminates. If no commands in the do actions are executed, then the while command returns a 0 exit status; until may be used in place of while to negate the loop termination test. csh While conditions is TRUE (evaluates to nonzero), repeat com- mands between the while and the matching end statement. The while and end must appear alone on their input lines. If the shell's input is a terminal, it prompts for commands with a question-mark until the end command is entered and then per- forms the commands in the loop. ksh A while command repeatedly executes the while conditions and, if the exit status of the last command in the condi- tions list is zero, executes the do actions; otherwise the loop terminates. If no commands in the do actions are exe- cuted, then the while command returns a 0 exit status; until may be used in place of while to negate the loop termination test. loop interrupts The built-in command continue may be used to terminate the execution of the current iteration of a while or until loop, SunOS 5.8 Last change: 15 Apr 1994 1 User Commands while(1) and the built-in command break may be used to terminate exe- cution of a while or until command.

EXAMPLES

Example 1: Using The while Command With sh and ksh In these examples, the user is repeated prompted for a name of a file to be located, until the user chooses to finish the execution by entering an empty line. filename=anything while [ $filename ] do echo "file?" read filename # read from terminal find . -name $filename -print done The brackets surrounding $filename are necessary for evalua- tion. (See the test built-in command in the if(1) man page). Additionally, there must be a blank space separating each bracket from any characters within. Example 2: Using The while Command With csh set filename = anything while ( "$filename" != "" ) echo "file?" set filename = $< # read from terminal find . -name $filename -print end

ATTRIBUTES

See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |_____________________________|_____________________________| | Availability | SUNWcsu | |_____________________________|_____________________________|

SEE ALSO

break(1), csh(1), if(1), ksh(1), sh(1), attributes(5)

NOTES

Both the Bourne shell, sh, and the Korn shell, ksh, can use the semicolon and the carriage return interchangeably in their syntax of the if, for, and while built-in commands. SunOS 5.8 Last change: 15 Apr 1994 2