Discussion:
[ast-developers] ksh: odd braceexpand behaviour
Michal Hlavinka
2013-07-08 17:09:31 UTC
Permalink
Hi,

it seems braceexpand option does not always affect expansions, sometimes
it depends on glob option.

$ a='{1..6}'
$ set -o | sed -n -e /glob/p -e /braceexpand/p
braceexpand on
glob on
globstar off

$ print $a
1 2 3 4 5 6

$ set +o braceexpand
$ set -o | sed -n -e /glob/p -e /braceexpand/p
braceexpand off
glob on
globstar off

$ print $a
1 2 3 4 5 6

$ set -o braceexpand
$ set +o glob
$ set -o | sed -n -e /glob/p -e /braceexpand/p
braceexpand on
glob off
globstar off

$ print $a
{1..6}

Seems braceexpand has no effect. Instead glob options
affects expansion.

Michal
Cyrille Lefevre
2013-07-08 21:42:30 UTC
Permalink
Post by Michal Hlavinka
Hi,
it seems braceexpand option does not always affect expansions, sometimes
it depends on glob option.
<snip>
Post by Michal Hlavinka
Seems braceexpand has no effect. Instead glob options
affects expansion.
a='{1,6}' b='{1..6}'
for i in -braceexpand +glob +braceexpand -glob; do
set ${i%${i#?}}o ${i#?}
set -o | sed -n -e 's/ */ /' -e /glob/p -e /braceexpand/p | tr '\n' '
';echo
print "$a" $a
print "$b" $b
print "{1,6}" {1,6}
print "{1..6}" {1..6}
done

$ uname -a
CYGWIN_NT-6.1 pcvista 1.7.18(0.263/5/3) 2013-04-19 10:39 i686 Cygwin
$ ksh93 -e 'print ${.sh.version}'
Version JM 93u 2011-02-08
$ ksh93 /tmp/f
braceexpand on glob on globstar off
{1,6} 1 6
{1..6} 1 2 3 4 5 6
{1,6} 1 6
{1..6} 1 2 3 4 5 6
braceexpand on glob off globstar off
{1,6} {1,6}
{1..6} {1..6}
{1,6} 1 6
{1..6} 1 2 3 4 5 6
braceexpand off glob off globstar off
{1,6} {1,6}
{1..6} {1..6}
{1,6} {1,6}
{1..6} {1..6}
braceexpand off glob on globstar off
{1,6} 1 6
{1..6} 1 2 3 4 5 6
{1,6} {1,6}
{1..6} {1..6}

well, braceexpand works ok for static values ({x..y}), but not for
dynamic values ($x), is this intended ?

unfortunatelly, {1..5,6} does partly work w/ braceexpand.

$ set -o | sed -n -e 's/ */ /' -e /glob/p -e /braceexpand/p | tr '\n' '
';echo
braceexpand on glob off globstar on
$ print {1..5,6}
1..5 6

Regards,

Cyrille Lefevre
--
mailto:Cyrille.Lefevre-lists at laposte.net
Loading...