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

Re: grammar triviality with '&&'



On Mon, 2 Mar 2015 11:46:19 +0100
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> Now, assume that as soon as some command fails, you don't want
> to execute the following ones, but you still want to have the
> 3 commands in the history when invoking the latest cmd1 by a
> history search (something I often do). Currently, the only way
> to do that is, AFAIK:
> 
> cmd1
> [[ $? -eq 0 ]] && cmd2
> [[ $? -eq 0 ]] && cmd3
> 
> But having
> 
> cmd1
> && cmd2
> && cmd3
> 
> could be nicer (I would also like the fact that one can easier see
> that these 3 commands are related).

% andfn() {
   integer stat=$?
   (( $stat > 0 )) && return $stat
   return 0
}
% alias and='andfn &&'

% print this worked
this worked
% and print so did this
so did this
% and { print but this failed; false; }
but this failed
% and print so this didn\'t get printed


-- 
Peter Stephenson | Principal Engineer Samsung Cambridge Solution Centre
Email: p.stephenson@xxxxxxxxxxx | Phone: +44 1223 434724 |
www.samsung.com



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