How to find out if a shell command exists in cshell

I am looking for a function that will return 1 if a shell command exists, and 0 otherwise I know that there is a command whichthat returns the path to the command if it exists. The manual also says that this command should have a return value, but trying to set a = `which some_command.bin`does not put any value in a. I know that I can always use which, then analyze the results, I'm just looking for a cleaner solution

+3
source share
1 answer

The return value for the shell command is usually not obtained this way. Usually you need to run the command, then a special environment variable $?will give you the return value.

Refer to the following entry for tcsh:

pax$ which qq ; echo $?
qq: Command not found.
1

pax$ which ls ; echo $?
/bin/ls
0

Just put any command you want to check where I have lsabove.

+5
source

Source: https://habr.com/ru/post/1789191/


All Articles