0

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?

Walter
  • 44,150
  • 20
  • 113
  • 196

1 Answers1

1

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
Ani
  • 918
  • 1
  • 10
  • 25