[The SHELL] determines whether a command is present

command -v db2 | wc -l
execute the command returns a value of 0, it means you can call the db2 command

command -v db2 | wc -l
execute the command returns a value of 1 indicates that not calling the db2 command, you need to configure the user environment variables

First to note is, do not use which to be judged for the following reasons:
1, which non-SHELL built-in command, use up larger than the built-in command overhead, and non-built-in commands will depend on the platform implementation, to achieve different platforms may be different .
Of the type of the type #
of the type IS A shell the BUILTIN
# the Command of the type
the Command IS A shell the BUILTIN
# of the type Which
Which IS hashed (/ usr / bin / Which)
2, Which many systems do not set the return value of the exit command even if you want to find It does not exist, which also returns 0

# which ls
/usr/bin/ls
# echo $?
0
# which aaa
no aaa in /usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/bin /usr/local/sbin /usr/ccs/bin /usr/openwin/bin /usr/dt/bin
# echo $?
0

3, which many system implementations are surreptitiously done some "difficult for outsiders also" things
so do not use which, you can use the following method:
$ foo the Command -v> / dev / null 2> & 1 || { echo> & 2. "the I the require foo But IT apos Not Installed the Aborting."; Exit. 1;}
$ type foo> / dev / null 2> &. 1 || {echo> & 2 "the I the require foo But IT apos Not Installed the Aborting.."; . 1 Exit;}
$ foo the hash 2> / dev / null || {echo> & 2 "foo But the require the I IT apos Not Installed the Aborting.."; Exit. 1;}


Guess you like

Origin blog.51cto.com/11310506/2413784