$# Number of arguments from the script's command line If $# is 0, then no options were given on the command line.
$* $@ All of the arguments from the script's command line When quoted, '$*' becomes a single block of text containing all of the arguments, while '$@' becomes separate words. If the script is called with the arguments 'green' and 'yellow', then '$*' would evaluate to 'green yellow', while '$@' would evaluate to 'green' 'yellow'.
$? Exit status of the last command Manpages document the possible exit-status values for most commands.

4.12.1.3. Control structures

Like most programming languages, bash features a number of control structures to enable looping and conditional execution. The three most common control structures are listed in Table 4-18 ; there is also a C-style for loop that I'll discuss in the next section.

Table 4-18. Common bash control structures

Structure Notes Example
for variable in list The variable is assigned the first value in list, and loop-commands are executed. The process is then repeated for all of the other values in list. # Set X to 'hosts', then display the filename and file contents. Repeat for 'services'
do for X in hosts services
loop-commands do
done echo '==== $X'
cat /etc/$X
done
if control-command If the control-command succeeds, the if-commands are executed; otherwise, the else-commands are executed. # Tell the user if the text 'test' appears in file1
then if grep -q test file1
if-commands then
[else echo 'Found it!'
else-commands] else
fi echo 'Not found.'
fi
while control-command As long as control-command executes successfully, loop-commands are repeated. # Display the free disk space every 2 seconds, forever
do while sleep 2
Вы читаете Fedora Linux
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату