Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-dev
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-dev@g.o
From: Steven J Long <slong@...>
Subject: Re: [RFC] obs eclasses
Date: Tue, 20 Sep 2011 06:09:03 +0100
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 ;-)




References:
[RFC] obs eclasses
-- Michal Hrusecky
Re: [RFC] obs eclasses
-- Amadeusz Żołnowski
Re: [RFC] obs eclasses
-- Joshua Kinard
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: [RFC] obs eclasses
Next by thread:
Re: [RFC] obs eclasses
Previous by date:
Re: udev and /usr
Next by date:
Re: udev and /usr


Updated Jun 29, 2012

Summary: Archive of the gentoo-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.