I have written this little script to find executables that are passed as arguments e.g.
./testexec du ls md
How do I get the script to not output commands that are not found – e.g. not to display error output for “md” command ??
#!/bin/sh
for filename in "$@"
do
which $filename
done
If you are using bash, you should use the builtin “type” rather than the external utility “which”. The type command will return a non-zero exit status if the command is not found, which makes it easy to use with a conditional.