From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 235 invoked by alias); 6 Aug 2015 06:03:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20387 Received: (qmail 5769 invoked from network); 6 Aug 2015 06:03:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Subject: Re: Incorporating (( $+commands[foo] )) into a larger "if" statement To: zsh-users@zsh.org References: From: id5 X-Enigmail-Draft-Status: N1110 Message-ID: <55C2F65F.50807@necoro.eu> Date: Thu, 6 Aug 2015 07:53:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit if [[ $+commands[foo] -ge 1 && ... ]]; then echo yes fi OR if [[ (( $+commands[foo] )) && ... ]]; then echo yes fi OR (the very straightforward way) if (( $+commands[foo] )); then if [[ ... ]]; then echo yes fi fi Also: Please note, that '[[' should be used instead of '[', for the former is way saner in its behavior. - René Am 06.08.2015 um 00:00 schrieb TJ Luoma: > OK, so I am apparently mis-understanding something or I've forgotten > something about how this works. > > Some time ago, someone from the list suggested that I could do this instead > of using `which` > > if (( $+commands[foo] )) > then > > echo yes > > fi > > > that works fine. However, what I am trying to do now is check for other > things at the same time. > > For example, if I want to check that the command `growlnotify` is found in > the $PATH and I want to check to see if `pgrep` finds 'Growl' is running. > In that instance I would use this to check `pgrep`: > > if [ "`pgrep -x Growl`" != "" ] > then > echo Not Running > else > echo Is Running > fi > > but I can't figure out how to put that together with > > if (( $+commands[growlnotify] )) > > OR, if I want to see if the command `bbedit` is found, and I want to check > that a variable $APP is equal to "bbedit". I would do the latter > > if [ "$APP:l" == "bbedit" ] > then > echo yes > else > echo no > fi > > > Any help would be appreciated. > > Thanks! > > TjL >