Книга: The Linux Command Line
Назад: IV. Writing Shell Scripts
Дальше: 26. Top-Down Design

, we discussed the PATH environment variable and its effect on how the system searches for executable programs. To recap, the system searches a list of directories each time it needs to find an executable program, if no explicit path is specified. This is how the system knows to execute /bin/ls when we type ls at the command line. The /bin directory is one of the directories that the system automatically searches. The list of directories is held within an environment variable named PATH. The PATH variable contains a colon-separated list of directories to be searched. We can view the contents of PATH:

, we looked at a particularly long example of the find command:

[me@linuxbox ˜]$ find playground \ ( -type f -not -perm 0600 -exec chmod 0600 '{}' ';' \)  -or \( -type d -not -perm 0700 -exec chmod 0700 '{}' ';' \)

This command is a little hard to figure out at first glance. In a script, this command might be easier to understand if written this way:

find playground \         \( \                 -type f \                 -not -perm 0600 \                 -exec chmod 0600 '{}' ';' \         \) \         -or \         \( \                 -type d \                 -not -perm 0700 \                  -exec chmod 0700 '{}' ';' \         \)

Through the use of line continuations (backslash-linefeed sequences) and indentation, the logic of this complex command is more clearly described to the reader. This technique works on the command line, too, though it is seldom used as it is very awkward to type and edit. One difference between a script and the command line is that a script may employ tab characters to achieve indentation, whereas the command line cannot because tabs are used to activate completion.

© RuTLib.com 2015-2018