public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Steven J Long <slong@rathaus.eclipse.co.uk>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] Re: [RFC] obs eclasses
Date: Tue, 20 Sep 2011 06:09:03 +0100	[thread overview]
Message-ID: <j596vc$7qe$1@dough.gmane.org> (raw)
In-Reply-To: 4E6F4BDA.70505@gentoo.org

Joshua Kinard wrote:

> On 09/13/2011 07:24, Amadeusz Żołnowski wrote:
> 
>> You don't need -n/-z with [[.
>> 
>>   [[ $var ]] == [[ -n $var ]]
>>   [[ ! $var ]] == [[ -z $var ]]
>>
Also, you can usually be more succinct with [[ $var ]] || { some code; } for 
the empty case (as opposed to [[ $var ]] && { something else; } for code run 
when var is non-empty.)

> What about other comparisons, like -f, -e, or -d?  Bash's manpage only
> says
> [[ expression ]] -- it doesn't seem to go into the level of detail (at
> least not in the section that I quickly perused) about what flag
> operators are necessary or not.
>
As Amadeusz said, you can't omit the other ones.

> Also, is this a bash4-only thing, or bash3 and/or bash2 as well?
>
It was definitely around in all bash-3 versions, from experience, and it's 
also a defined behaviour for POSIX sh test or [, tho only guaranteed for XSI 
systems[1] so I'd be surprised if it weren't in bash-2.

> If yes to above, we should get this edited and fixed up, then, because it
> uses -z/-n inside [[ ]]:
> http://devmanual.gentoo.org/tools-reference/bash/index.html
>
As Michal said, it doesn't do any harm. imo it'd be better just to add that 
[[ $var ]] is the same as [[ -n $var ]]. [[ ! $var ]] doesn't seem better 
than [[ -z $var ]] to my eyes; the latter is clearer imo.

(Decrufting ${var} to $var would be more of a help for learners imo; you 
only need to wrap a simple variable expansion in {} when it's immediately 
followed by an alphanumeric or underscore character, which would get 
interpreted as part of its name, which any syntax highlighting editor will 
show you. In several years of BASH scripting I've only once had an issue 
with that, in some complex text output.)
> Oh, forgot, it won't break initscripts, will it?
> 
Well you wouldn't use [[ in a sh-compatible initscript in any case. There 
it'd be safest to stick to [ -n "$var" ] (or -z ofc.)

[1] http://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html
-- 
#friendly-coders -- We're friendly, but we're not /that/ friendly ;-)





  parent reply	other threads:[~2011-09-20  5:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-13 11:11 [gentoo-dev] [RFC] obs eclasses Michal Hrusecky
2011-09-13 11:24 ` Amadeusz Żołnowski
2011-09-13 12:26   ` Joshua Kinard
2011-09-13 13:02     ` Amadeusz Żołnowski
2011-09-13 13:12       ` Michał Górny
2011-09-13 14:44       ` Donnie Berkholz
2011-09-13 15:58         ` Patrick Lauer
2011-09-13 16:41           ` Donnie Berkholz
2011-09-13 17:25             ` Ulrich Mueller
2011-09-13 17:33               ` Tomáš Chvátal
2011-09-13 17:38               ` Amadeusz Żołnowski
2011-09-13 17:40               ` Michał Górny
2011-09-13 18:40                 ` Ulrich Mueller
2011-09-13 18:47                   ` Michał Górny
2011-09-14  5:39             ` Ciaran McCreesh
2011-09-14  5:37           ` Ciaran McCreesh
2011-09-20  5:09     ` Steven J Long [this message]
2011-09-13 14:37   ` Michal Hrusecky
2011-09-13 14:59 ` Donnie Berkholz
2011-09-13 15:55   ` Nirbheek Chauhan
2011-09-14  8:44   ` Michal Hrusecky
2011-09-14  8:56 ` Michal Hrusecky
2011-09-14  9:56   ` Ulrich Mueller
2011-09-14 13:34     ` Michal Hrusecky
2011-09-15  7:35   ` Marijn
2011-09-15  8:18     ` Michal Hrusecky
2011-09-15 16:30       ` [gentoo-dev] " Duncan
2011-09-20  8:23 ` [gentoo-dev] " Michał Górny
2011-09-20  9:26   ` Tomáš Chvátal

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='j596vc$7qe$1@dough.gmane.org' \
    --to=slong@rathaus.eclipse.co.uk \
    --cc=gentoo-dev@lists.gentoo.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox