Gentoo Archives: gentoo-dev

From: Mike Gilbert <floppym@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] RFC: esethome
Date: Fri, 15 Jun 2012 14:25:33
Message-Id: CAJ0EP41v_fA0YEFQ41gPAR_db3bcMsui6sceY45x+LGE=mMaUA@mail.gmail.com
In Reply to: Re: [gentoo-dev] RFC: esethome by Peter Stuge
1 On Fri, Jun 15, 2012 at 10:05 AM, Peter Stuge <peter@×××××.se> wrote:
2 > Fabian Groffen wrote:
3 >> > > >>> +       if [[ ! -n $(egetent passwd "${euser}") ]] ; then
4 >> > > >>
5 >> > > >> "! -n" -> "-z"
6 >> > > >
7 >> > > > Does the $() argument ever need to be double quoted, or do all
8 >> > > > versions of bash actually have the string argument optional even
9 >> > > > though that's not what the man page reads?
10 >> > >
11 >> > > Ever?  Yes, but only if what is being returned can contain spaces
12 >> >
13 >> > Sorry, I should have mentioned that I had the case of the empty
14 >> > string in mind.
15 >>
16 >> Here for the same reason, the difference between [[ and [ is essential.
17 >
18 > It's not clear to me why?
19 >
20 > [] is shorthand for test. Both test and [[]] in my man bash read:
21 >
22 > --8<--
23 > Expressions are composed of the primaries described .. under
24 > CONDITIONAL EXPRESSIONS.
25 > -->8--
26 >
27 > There it says:
28 > --8<--
29 > Conditional expressions are used by the [[ compound command and
30 > the test and [ builtin commands
31 > -->8--
32 >
33 > and:
34 > --8<--
35 >       -z string
36 >              True if the length of string is zero.
37 >       string
38 >       -n string
39 >              True if the length of string is non-zero.
40 > -->8--
41 >
42 > ..which does not at all make it clear that the string is actually
43 > optional?
44 >
45 > Under Command Substitution it says:
46 > --8<--
47 > Embedded newlines are not deleted, but they may be removed during
48 > word splitting.
49 > ..
50 > If the substitution appears within double quotes, word splitting
51 > and pathname expansion are not performed on the results.
52 > -->8--
53 >
54 > ..confirming that there is some processing of the substitution.
55 >
56 >
57 > I also did the tests before asking the question. I'm not trying to
58 > say that the code doesn't work on my system. I'm asking if it will
59 > work the same on every version of bash, in spite of what seems to
60 > be a conflict between real world and documentation.
61 >
62 >
63 > //Peter
64
65 Word splitting does not occur within double brackets. This is
66 documented in the bash manual.
67
68 http://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs
69
70 This causes empty output from a command substitution within double
71 brackets to be treated as a zero-length string.

Replies

Subject Author
Re: [gentoo-dev] RFC: esethome Peter Stuge <peter@×××××.se>