开发者

Shell Scripting - check java bin

开发者 https://www.devze.com 2023-01-04 06:48 出处:网络
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:

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

精彩评论

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