Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh: The shortest check if "program" exist (on current PATH)?

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
I wold like to replace:

type lsof >/dev/null 2>&1 && ( [ $? -eq 0 ] && echo is ) || echo is not

with the shorter method - getting exit code of "type" directly in [ ...... ] - [ GETEXITCODE_of`type lsof >/dev/null 2>&1' -eq 0 ] && ....


thx in advance,
rm.
 

[ `type llsof >/dev/null 2>&1;echo $?` -eq 0 ] && echo is || echo is not

maybe shorter test?
 
And what about this ?
[ -z "$(whence lsof)" ] && echo is not || echo is

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
whence?
The thread title clearly say that the OP uses ksh.
man ksh said:
[tt]whence [ -pv ] name ...
For each name, indicate how it would be interpreted if
used as a command name.
whence accepts the following options:
-v
Produce a more verbose report.
-p
Do a path search for name even if name is an alias, a
function, or a reserved word.[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top