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

Re: A short form for if-then-else



2009/10/15 Anonymous bin ich <ichbinanon@xxxxxxxxx>:
> Hi!
>
> 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?

if which mailx &> /dev/null; then
  foo
else
  bar
fi

-- 
Mikael Magnusson



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