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

Re: [[ -x =command ]]



Atom Smasher <atom@xxxxxxxxxxx>:
> as i understand the documentation, this should either return 0 or !0 
> depending on whether a command "foo" can be found in the path:
> 	[[ -x =foo ]]
>
> but if =foo can't be found, it craps out.
>
> i've got this in my ~/.zshrc:
> 	[[ -x =most ]] && export PAGER=most
>
> and i would expect that if "most" isn't in my path, nothing would happen 
> (nothing, in this case, meaning the PAGER variable remains unset)... 
> instead what actually happens that processing of ~/.zshrc dies with an 
> error. not good!
>
> so....
> a) should that work the way i'm doing it?

No.
If 'most' is not in $path, =most can not be expanded, which will cause
the error.

> b) if not, what's the correct way to test if a command exists in the PATH?

[[ -x $(which most) ]] && echo yay || echo nay

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



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