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

Re: A short form for if-then-else



Anonymous bin ich <ichbinanon@xxxxxxxxx>:
> I want to check if a program (mailx) is present or not. If present,
> the program will be run, if not, an error message should be printed.
> No other message should be printed.
> 
> I have tried following ways:
> 
> which mailx &>/dev/null && mailx || echo "not found"
> 
> but when mailx exits with non 0 error code, "not found" is printed.
> 
> I tried
> 
> if [[ -x =mailx ]]; then mailx; else echo "not found"; fi
> 
> but when mailx is not present, zsh prints an error which I cannot seem
> to redirect to /dev/null
> 
> Any other way to do it without involving local variables or different
> external programs?

Yeah, that question had an in-depth thread last time it came up. So,
you may be interested in this:
    <http://www.zsh.org/mla/users/2007/msg00918.html>

Answers discuss various possible solutions, as well as their up- and
downsides.

Regards, Frank



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