开发者

Shell Scripting - check java bin

On a unix machine,开发者_Go百科 how can I write a shell script for checking if 'java bin' directory has been included in $PATH env. variable?


It's probably simplest to use which:

which java || exit 1


if which java >/dev/null 2>&1 ; then
  echo yes
fi


Since the directory name can be anything, this would be a bit hard to check by looking at the $PATH variable, but you could try looking at the return value of a command like which javac.


which is appropriate, but only checks for your command defined in $PATH. What if javac is not defined in $PATH but it is installed somewhere else? In that extreme case, you use find or locate to find where javac is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜