while(1) manual page
Table of Contents
while, until - shell built-in functions to repetitively execute a
set of actions while/until conditions are evaluated TRUE
while
[ conditions ]; do actions ; done
- until [ conditions ]; do actions ;
done
-
while (conditions)
... # do actions
end
while [ conditions ]; do actions ; done
- until [ conditions ];
do actions ; done
-
SUNWcsu
A while command
repeatedly executes the while conditions and, if the exit status of the
last command in the conditions 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.
While conditions is TRUE
(evaluates to nonzero), repeat commands 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 performs the commands in the
loop.
A while command repeatedly executes the while conditions and, if
the exit status of the last command in the conditions list is zero, 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.
The built-in command continue may be used to terminate the execution
of the current iteration of a while or until loop, and the built-in command
break may be used to terminate execution of a while or until command.
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 evaluation. (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.
set filename = anything
while ( "$filename" != "" )
echo "file?"
set filename = $< # read from terminal
find . -name $filename -print
end
Use the same syntax as in the Bourne shell, sh, example above.
break(1)
,
csh(1)
, if(1)
, ksh(1)
, sh(1)
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.
Table of Contents