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 out
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.
for filename in "$@"; do
if type -P "$filename" >/dev/null; then
echo "found in PATH: $filename"
fi
done
Just redirect the error message (coming from stderr
) into /dev/null
:
which $filename 2>/dev/null