====== Ubuntu - Bash - Scripts - paths ======
**paths** displays the directory where the file is located
... provides name of the file in a long format or looking for files with the bit Polish
zovatelskogo identifier (setuid bit files) in the directory specified.
It uses the PATH environment variable which holds directory names, separated by a colon (:).
Paths has three main functions.
* It can run as a main command path, to give full route of the executable name.
* It may provide a file format in a long route.
* It can also give a list of all files installed with the user identification (setuid bit files), which are in your routing directories.
The syntax of the call is a little different for different options. To use the format of the route or the issuance of the ls command format required this command line:
paths [-l] file [file ...]
as, for example, in the commands
"paths ls who date"
or
"paths -l ll"
----
For Search files with set user ID (setuid files) do not need to specify the file names on the command line. It should be:
paths -s
Format setuid and output formats of the route are mutually exclusive conductive.
What and where are the files, rather than to guess file names.
If there is some other option on the command line, the standard output an error message and the batch file pro-commits. Options set the output format flag in one of the three values. The rest of the output from the batch file is controlled by the selected output format.
----
===== Usage =====
paths [-l] [-s] file [file ...]
* ARG contains each command-line argument
* DIR element with a directory name in the PATH
* FILE contains the name of each file on the command line
* FORMAT Type the desired output format
* IFS shell variable, the field separator
* PATH shell variable, the path to the executable directory modules.
----
===== Code =====
#!/bin/bash
#
# @(#) paths v1.0 Path locator with special options.
#
FORMAT="path"
for ARG in $@
do
if [ '`echo $ARG | cut -c1`" = "-" ]
then case $ARG in
-l) FORMAT="ls"
shift;;
-s) FORMAT="set"
set "1";;
*) echo $0: arg error" >&2
echo "usage: $0 [-l] [-s] file [file ...]" >&2
exit 1;;
esac
fi
done
IFS="${IFS}:"
for FILE in $@
do
for DIR in $PATH
do
case $FORMAT in
path) if [ -f $DIR/$FILE ]
then echo $DIR/$FILE
fi;;
ls) if [ -f $DIR/$FILE ]
then ls -l $DIR/$FILE
fi;;
set) echo "\n:::::::::::::::::::"
echo "$DIR"
echo "::::::::::::::::::::"
ls -al $DIR | grep "^[^ ]*s[^ ]*";;
esac
done
done
----
===== Example Usage =====
paths -l ed ex vi
----
Search route commands ls, more, who, paths. In the derivation of indicated out to be full of the absolute route names. Note that After the name of each file is printed newline to semiconductor chit listing in which each file name is on a separate line.
paths ls more who paths
result:
/bin/ls
/usr/bin/more
/bin/who
/usr/john/bin/paths
----
If your PATH variable includes the directory /etc, then this example will work.
If not, the first two files are not found.
When the **paths** command is run, its output is put into place into the command line.
When you start the more command, it does not know that its arguments are being derived.
more `paths gettydefs termcap paths`
result:
more /etc/gettydefs /etc/termcap /usr/john/bin/paths
with the full path name of each file.
This example illustrates how you can make the command **paths** do all the work of finding and using files that you want to see.
----
In this example, the output file names ll in the long format, that finds path. (We will be presenting our version of the command ll more
later in this chapter.) As in the previous case, is generated first etsya information about the route, then it is placed in the command line, and ll then run the command.
ll `paths ll`
----
In this example, the generated path name of the command file paths and transmitted m program which uses the more command to print. (M command file we will show you later.)
m `paths paths`