$# | 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,
Table 4-18. Common bash control structures
Structure | Notes | Example |
---|---|---|
for | The | # Set X to 'hosts', then display the filename and file contents. Repeat for 'services' |
do | for X in hosts services | |
do | ||
done | echo '==== $X' | |
cat /etc/$X | ||
done | ||
if | If the | # Tell the user if the text 'test' appears in file1 |
then | if grep -q test file1 | |
then | ||
[else | echo 'Found it!' | |
else | ||
fi | echo 'Not found.' | |
fi | ||
while | As long as | # Display the free disk space every 2 seconds, forever |
do | while sleep 2 |
Вы читаете Fedora Linux