Gentoo Archives: gentoo-user

From: Kerin Millar <kerframil@×××××××××××.uk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] bash script question
Date: Mon, 18 Aug 2014 14:18:15
Message-Id: 53F20B1B.20803@fastmail.co.uk
In Reply to: Re: [gentoo-user] bash script question by Stroller
1 On 18/08/2014 15:02, Stroller wrote:
2 >
3 > On Mon, 18 August 2014, at 1:16 pm, Kerin Millar <kerframil@×××××××××××.uk> wrote:
4 > ...
5 >> (( count += matches ))
6 >> done < <(grep -hcm1 -F "$string" ${files[*]})
7 >
8 > Oh, this is lovely.
9 >
10 > I've learned some things today.
11 >
12 >> if (( count == ${#files[@]} )); then
13 >
14 > May I ask why you prefer these brackets for evaluation, please?
15
16 There was no particular reason, other than to maintain consistency in
17 the example (both for evaluation and as an alternative to expansion).
18 Sometimes, I find double square brackets to be a bit of an eyesore, but
19 do tend to use them more often than not.
20
21 I particularly like double parentheses for checking exit codes assigned
22 to variables. For example:
23
24 (( $? )) && echo "something went wrong"
25
26 As opposed to having to perform an explicit comparison:
27
28 [[ $? != 0 ]] && echo "something went wrong"
29
30 --Kerin

Replies

Subject Author
Re: [gentoo-user] bash script question Kerin Millar <kerframil@×××××××××××.uk>