2

I would like to have something like this

if (command_not_exists) exit

Can someone tell me how to achieve this functionality in a cshell script?

10 Rep
  • 2,217
  • 7
  • 19
  • 33
BluVio
  • 449
  • 1
  • 5
  • 11
  • Welcome to StackOverflow. In other languages there is a function try to do so, maybe in csh there is something similar... – llrs Feb 26 '14 at 12:06
  • 1
    My problem is solved using the solution at [link](http://stackoverflow.com/questions/11137577/how-to-find-from-within-a-csh-script-whether-a-certain-command-is-available?rq=1) : if(`where test_cmd` == "") then echo " test_cmd: Command not found "; exit(1); endif thanks @Llopis – BluVio Feb 26 '14 at 12:23
  • If it is solved then answer your own question and accept it to close the question. So other people know how to do so, and prevent others to search a solution for this question :D – llrs Feb 26 '14 at 12:31

1 Answers1

6

My problem is solved using where command (I was trying with which command). Solution:

   if(`where test_cmd` == "") then
      printf "\ntest_cmd: Command not found\n";
      exit(1);
   endif

Thanks

BluVio
  • 449
  • 1
  • 5
  • 11
  • In case `tcsh` is the shell and the variable `printexitvalue` is set it does not work because `where test_cmd` evaluates to `Exit 1` if `test_cmd` does not exist. I.e. in shell scripts you want to unset `printexitvalue` first. – holger Jan 15 '16 at 10:03
  • `where` does not exist for me (`csh` version `20110502-3ubuntu0.18.04.1`). – pentavalentcarbon Jan 27 '21 at 22:14