Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Check existence of a program



Hello!

I am having trouble checking for existence of a program.

This works:

% cat working.zsh
#!/bin/zsh
set -x
prog="identify"
path=$(which ${prog})
%
% ./working.zsh
+./working.zsh:3> prog=identify
+./working.zsh:4> path=+./working.zsh:4> which identify
+./working.zsh:4> path=/usr/bin/identify
%

But this doesn't:

% cat notworking.zsh
#!/bin/zsh
set -x
prog="exiftime"
path=$(which ${prog})
if [[ ${?} -ne 0 ]]; then
    prog="identify"
    path=$(which ${prog})
fi
%
% ./notworking.zsh
+./notworking.zsh:3> prog=exiftime
+./notworking.zsh:4> path=+./notworking.zsh:4> which exiftime
+./notworking.zsh:4> path='exiftime not found'
+./notworking.zsh:5> [[ 1 -ne 0 ]]
+./notworking.zsh:6> prog=identify
+./notworking.zsh:7> path=+./notworking.zsh:7> which identify
+./notworking.zsh:7> path='identify not found'
%

Any idea?



Messages sorted by: Reverse Date, Date, Thread, Author