zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: TJ Luoma <tj@luo.ma>
Cc: Alex Satrapa <grail@goldweb.com.au>, Zsh-Users List <zsh-users@zsh.org>
Subject: Re: trying to create a "|| failed" function
Date: Fri, 15 Mar 2013 01:08:12 -0400	[thread overview]
Message-ID: <20130315050812.GA6596@redoubt.spodhuis.org> (raw)
In-Reply-To: <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


      reply	other threads:[~2013-03-15  5:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-15  1:39 TJ Luoma
2013-03-15  1:55 ` Alex Satrapa
2013-03-15  3:19   ` TJ Luoma
2013-03-15  5:08     ` Phil Pennock [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130315050812.GA6596@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=grail@goldweb.com.au \
    --cc=tj@luo.ma \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).