0% found this document useful (0 votes)
21 views

$path: 2.5 The Test Command

The document discusses various shell variables and commands used in Unix/Linux shells. It describes what the $PATH variable is and how it is used to locate executable files when commands are run. It also summarizes some common test conditions used with the test command, such as checking if a file exists or is readable. Finally, it provides an overview of how while loops work by repeating command-list2 as long as command-list1 returns a zero exit status.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

$path: 2.5 The Test Command

The document discusses various shell variables and commands used in Unix/Linux shells. It describes what the $PATH variable is and how it is used to locate executable files when commands are run. It also summarizes some common test conditions used with the test command, such as checking if a file exists or is readable. Finally, it provides an overview of how while loops work by repeating command-list2 as long as command-list1 returns a zero exit status.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

cat wn

will print on the terminal the file wn in this directory. The command cd with no argument is equivalent to
cd $HOME

This variable is also typically set in the the user's login profile. $PATH A list of directories that contain commands (the search path). Each time a command is executed by the shell a list of directories is searched for an executable file. If $PATH is not set then the current directory, /bin, and /usr/bin are searched by default. Otherwise $PATH consists of directory names separated by :. For example,
PATH=:/usr/fred/bin:/bin:/usr/bin

specifies that the current directory (the null string before the first :), /usr/fred/bin, /bin and /usr/bin are to be searched in that order. In this way individual users can have their own `private' commands that are accessible independently of the current directory. If the command name contains a / then this directory search is not used; a single attempt is made to execute the command. $PS1 The primary shell prompt string, by default, `$ '. $PS2 The shell prompt when further input is needed, by default, `> '. $IFS The set of characters used by blank interpretation (see section 3.4).

2.5 The test command


The test command, although not part of the shell, is intended for use by shell programs. For example,
test -f file

returns zero exit status if file exists and non-zero exit status otherwise. In general test evaluates a predicate and returns the result as its exit status. Some of the more frequently used test arguments are given here, see test (1) for a complete specification. test s true if the argument s is not the null string test -f file

true if file exists test -r file true if file is readable test -w file true if file is writable test -d file true if file is a directory

2.6 Control flow - while


The actions of the for loop and the case branch are determined by data available to the shell. A while or until loop and an if then else branch are also provided whose actions are determined by the exit status returned by commands. A while loop has the general form
while command-list1 do command-list2 done

The value tested by the while command is the exit status of the last simple command following while. Each time round the loop command-list1 is executed; if a zero exit status is returned then commandlist2 is executed; otherwise, the loop terminates. For example,
while test $1 do ...

You might also like