[git commit] hush: specially handle [[ - suppress globbing & multiword expansion

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 10 12:06:41 UTC 2009


On Wed, Jun 10, 2009 at 3:07 AM, Mike Frysinger<vapier at gentoo.org> wrote:
> On Tuesday 09 June 2009 17:17:07 Denys Vlasenko wrote:
>> On Tue, Jun 9, 2009 at 9:21 PM, Mike Frysinger<vapier at gentoo.org> wrote:
>> > On Tuesday 09 June 2009 12:40:52 Denys Vlasenko wrote:
>> >> commit:
>> >> http://git.busybox.net/busybox/commit/?id=9d617c44d2b1135d14b7dafd01a1d3
>> >>992 293f4d9 branch:
>> >> http://git.busybox.net/busybox/commit/?id=refs/heads/master
>> >>
>> >>
>> >> It's a bashism, but is surprisingly easy to do and costs very little
>> >> code.
>> >
>> > we dont want [[...]] because it implies a lot of extended operators that
>> > only bash supports: pattern matching, regexes, etc...
>>
>> (pattern matching? I know only about &&, || and =~ inside [[ ]])
>
> the rhs is always a pattern which is why it should be quoted to avoid
> accidental expansion in variables
> [[ bab == *a* ]]

Wow. I didn't know that. Let me check bash...

# [[ *a* == bab ]] && echo YES
# [[ bab == *a* ]] && echo YES
YES

Shocking. Our [[ ]] does not do that for sure...

My current knowledge about [[ ]] is:

// Basically, word splitting and pathname expansion should NOT be performed
// Examples:
// no word splitting:     a="a b"; [[ $a = "a b" ]]; echo $? should print "0"
// no pathname expansion: [[ /bin/m* = "/bin/m*" ]]; echo $? should print "0"
// Additional operators:
// || and && should work as -o and -a
// =~ regexp match
// == should do _pattern match_ against right side. bash does this:
//      # [[ *a* == bab ]] && echo YES
//      # [[ bab == *a* ]] && echo YES
//      YES
// != does the opposite
// Apart from the above, [[ expr ]] should work as [ expr ]

Am I missing anything above?

>> I intend to be friendly even for bash-loving heretics :)
>
> i dont have a problem with bash (i advocate it when writing development
> scripts), but i dont think it generally has a place on embedded systems.
>
>> > if anything, there needs to be a nob to turn all the bashisms off
>>
>> I will make such a knob.
>
> if there is a knob, then i say add all the bashisms to your hearts content

Just added it.
--
vda


More information about the busybox mailing list