From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Incorporating (( $+commands[foo] )) into a larger "if" statement
Date: Wed, 5 Aug 2015 18:57:50 -0700 [thread overview]
Message-ID: <150805185750.ZM22006@torch.brasslantern.com> (raw)
In-Reply-To: <CADjGqHusnMC08QWvBj_rPhGq0E_HXgXjZ7vzWBKPY8+Er1Tebw@mail.gmail.com>
On Aug 5, 6:00pm, TJ Luoma wrote:
}
} if (( $+commands[foo] ))
$+commands[foo] is either 1 (commands[foo] is set) or 0 (not set).
The (( )) are a math context evaluation, so (( 1 )) is true. This
whole expression is a single shell command, so it can be used in any
position that an ordinary shell command can be used.
Thus to use this with other tests, you can either:
- Combine the test forms with && or || like:
if (( $+commands[growlnotify] )) && [ "`pgrep -x Growl`" != "" ]
- Test for 1 or 0 within the ordinary test such as:
if [ $+commands[growlnotify] = 1 -a "`pgrep -x Growl`" != "" ]
next prev parent reply other threads:[~2015-08-06 1:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-05 22:00 TJ Luoma
2015-08-06 1:57 ` Bart Schaefer [this message]
2015-08-06 5:53 ` id5
2015-08-06 14:57 ` Bart Schaefer
2015-08-06 20:59 ` René Neumann
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=150805185750.ZM22006@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--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).