Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Re: [gentoo-commits] gentoo-x86 commit in sys-fs/udev: ChangeLog udev-115-r6.ebuild
Date: Tue, 25 Sep 2007 00:34:15
Message-Id: 200709242020.56925.vapier@gentoo.org
In Reply to: [gentoo-dev] Re: [gentoo-commits] gentoo-x86 commit in sys-fs/udev: ChangeLog udev-115-r6.ebuild by Duncan <1i5t5.duncan@cox.net>
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

Attachments

File name MIME type
signature.asc application/pgp-signature