1 |
Fabian Groffen wrote: |
2 |
> > > >>> + if [[ ! -n $(egetent passwd "${euser}") ]] ; then |
3 |
> > > >> |
4 |
> > > >> "! -n" -> "-z" |
5 |
> > > > |
6 |
> > > > Does the $() argument ever need to be double quoted, or do all |
7 |
> > > > versions of bash actually have the string argument optional even |
8 |
> > > > though that's not what the man page reads? |
9 |
> > > |
10 |
> > > Ever? Yes, but only if what is being returned can contain spaces |
11 |
> > |
12 |
> > Sorry, I should have mentioned that I had the case of the empty |
13 |
> > string in mind. |
14 |
> |
15 |
> Here for the same reason, the difference between [[ and [ is essential. |
16 |
|
17 |
It's not clear to me why? |
18 |
|
19 |
[] is shorthand for test. Both test and [[]] in my man bash read: |
20 |
|
21 |
--8<-- |
22 |
Expressions are composed of the primaries described .. under |
23 |
CONDITIONAL EXPRESSIONS. |
24 |
-->8-- |
25 |
|
26 |
There it says: |
27 |
--8<-- |
28 |
Conditional expressions are used by the [[ compound command and |
29 |
the test and [ builtin commands |
30 |
-->8-- |
31 |
|
32 |
and: |
33 |
--8<-- |
34 |
-z string |
35 |
True if the length of string is zero. |
36 |
string |
37 |
-n string |
38 |
True if the length of string is non-zero. |
39 |
-->8-- |
40 |
|
41 |
..which does not at all make it clear that the string is actually |
42 |
optional? |
43 |
|
44 |
Under Command Substitution it says: |
45 |
--8<-- |
46 |
Embedded newlines are not deleted, but they may be removed during |
47 |
word splitting. |
48 |
.. |
49 |
If the substitution appears within double quotes, word splitting |
50 |
and pathname expansion are not performed on the results. |
51 |
-->8-- |
52 |
|
53 |
..confirming that there is some processing of the substitution. |
54 |
|
55 |
|
56 |
I also did the tests before asking the question. I'm not trying to |
57 |
say that the code doesn't work on my system. I'm asking if it will |
58 |
work the same on every version of bash, in spite of what seems to |
59 |
be a conflict between real world and documentation. |
60 |
|
61 |
|
62 |
//Peter |