Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: trying to create a "|| failed" function
- X-seq: zsh-users 17703
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: TJ Luoma <tj@xxxxxx>
- Subject: Re: trying to create a "|| failed" function
- Date: Fri, 15 Mar 2013 01:08:12 -0400
- Cc: Alex Satrapa <grail@xxxxxxxxxxxxxx>, Zsh-Users List <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201210; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=qxxMMoHIwOKDJ/shBX8vhNQ/azqWu0kLSMlzpcQsXEw=; b=iQimqd6L2GunnOs3oKs8jXk98ASZyBhCwHeuqr5tPUPXaBiMl4sGL3DuOPPN8JHXVyuL3picvNLmUHU1pmX+Jsj2vVbU4/TTNVFb3n2uCuWtTvn0VGTU2Y4MSa2+B5Byoq1Qve5lCtFLUbTsF4RJAjwI9LeFIJNhRPOzC+rcSVk=;
- In-reply-to: <CADjGqHu7f+4-=Tq2w1zd6OB-sA+zK_NE9S5eEn55AfRAwjnoHg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: TJ Luoma <tj@xxxxxx>, Alex Satrapa <grail@xxxxxxxxxxxxxx>, Zsh-Users List <zsh-users@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHu2rLLEReGyzBOnVbkvEiz+DCR3fMwjf11ACJGeds1q5A@mail.gmail.com> <C553B1A4-239C-49A9-98FD-1567C3F5936E@goldweb.com.au> <CADjGqHu7f+4-=Tq2w1zd6OB-sA+zK_NE9S5eEn55AfRAwjnoHg@mail.gmail.com>
On 2013-03-14 at 23:19 -0400, TJ Luoma wrote:
> OUTPUT=`$@ 2>&1`
> # failed
> echo "$NAME [$TIME]: $@ failed\nOUTPUT: >$OUTPUT<\nExit: >$EXIT<" | tee -a
> "$LOG"
> Anything I can or "should" do differently in the function above?
OUTPUT=`"$@" 2>&1`
Because: $@ drops empty elements, so passing empty parameters to a
command will be dropped, which leads to interesting debugging sessions.
Then in the echo line I quoted, you probably want $* instead of $@
because this is an echo message and you don't want it split apart.
% foo() { echo "snert $@ ni" }
% foo alpha beta
snert alpha ni snert beta ni
%
That's caused by "setopt rc_expand_param" being turned on.
So: $@ is a good habit to get into using, but you usually want "$@",
even in zsh, and for echo situations, you still want $*.
-Phil
Messages sorted by:
Reverse Date,
Date,
Thread,
Author