Walter
Walter

Reputation: 45444

How to find from within a csh script whether a certain command is available?

In a csh script, I need to perform something only if a certain command is available. I wanted to do something like

if( _WHAT_TO_PUT_HERE_ ) then   # enter only if command "cmd" is in the path
   cmd ...
endif

how to do that in csh or tcsh?

Upvotes: 0

Views: 177

Answers (1)

Ani
Ani

Reputation: 1018

I guess using the where command will solve your issue

Check this:

~/animesh >where grep
/bin/grep
/tools/cfr/bin/grep
~/animesh >where egrep
/bin/egrep
/tools/cfr/bin/egrep
~/animesh >where xgrep
~/animesh >

so lets say you are trying to find a command named my_cmd try the following code:

if(`where my_cmd` != "") then
   my_cmd
endif

Upvotes: 1

Related Questions