Reputation: 879
On a unix machine, how can I write a shell script for checking if 'java bin' directory has been included in $PATH env. variable?
Upvotes: 2
Views: 2568
Reputation: 342363
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.
Upvotes: 0
Reputation: 3477
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
.
Upvotes: 1
Reputation: 175375
It's probably simplest to use which
:
which java || exit 1
Upvotes: 7