1 |
On Monday 24 September 2007, Duncan wrote: |
2 |
> Donnie Berkholz <dberkholz@g.o> posted: |
3 |
> > For tests, pick a style |
4 |
> > [[ ]] or [ ] and stick with it. The [[ ]] one is pretty nice because it |
5 |
> > generally doesn't require quotes, so the code looks a lot cleaner. |
6 |
> |
7 |
> Can you point me (and anyone else that may be interested) to a nice |
8 |
> explanation of the difference? |
9 |
|
10 |
i use `man bash` myself ... |
11 |
|
12 |
> I've always wondered why [[ ]] is |
13 |
> considered "better" than [ ] for tests. |
14 |
|
15 |
as Donnie pointed out, it handles quoting sanely ... it also allows for |
16 |
extended bash logic tests (like matching and regexps) as well as your |
17 |
standard logic operators |
18 |
|
19 |
fails: |
20 |
f="moo cow with space" |
21 |
[ ${f} = blah ] |
22 |
works: |
23 |
[[ ${f} == blah ]] |
24 |
|
25 |
wildcards: |
26 |
[[ ${f} == *moo* ]] |
27 |
|
28 |
C logic operators (rather than crappy shell '-a' / '-o' / etc...): |
29 |
[[ moo == foo || moo == moo && blah == doit ]] |
30 |
-mike |