weird bash script error

Natanael Copa natanael.copa at gmail.com
Wed Jul 18 08:44:39 UTC 2007


On Wed, 2007-07-18 at 00:25 +0100, Denis Vlasenko wrote:
> On Tuesday 17 July 2007 07:16, Juan Martin wrote:
> > Hi, Denis!
> > 
> > OK sorry, here it goes.
> > 
> > Setup.sh reads BlackBox.conf varsets, and build a set of vars with cfg_ 
> > prefix then it prints it to console (just for cheap debugging as well as 
> > echo lines) output contain these lines.
> > 
> > I guess Paul Fox is right and "awk" has to be blamed so...
> 
> Well, it's rather easy to reduce it to trivial testcase:
> 
> echo "GNU awk:"
> echo "[set_1]" | /usr/bin/awk -F '[][]' 'NF==3 && $0 ~ /^\[.*\]/ { print $2 }'
> echo "Bbox awk:"
> echo "[set_1]" | /bin/awk -F '[][]' 'NF==3 && $0 ~ /^\[.*\]/ { print $2 }'
> echo "End"
> 
> # sh Setup1.sh
> GNU awk:
> set_1
> Bbox awk:
> End
> 
> Yes, awk is guilty.

Its the splitting of the fields that differs.

echo "[set_1]" | /usr/bin/awk -F '[][]' 'NF==3 { print($2) }'
set_1

echo "[set_1]" | ./busybox awk -F '[][]' 'NF==3 { print($2) }'
<missing output here>

echo "[set_1]" | ./busybox awk -F '[][]' 'NF==2 { print($2) }'
set_1

echo "[set_1]" | /usr/bin/awk -F'[][]' '{print NF}'
3

echo "[set_1]" | ./busybox awk -F'[][]' '{print NF}'
2

What is the regex '[][]' supposed to match?

Workaround for this specific case:
echo "[set_1]" | ./busybox awk -F '[][]' '$0 ~ /^\[.*\]$/ { print($2) }'


Natanael Copa





More information about the busybox mailing list