Parameter expansion stopped working in recent ash/dash
Brian Inglis
Brian.Inglis@Shaw.ca
Tue Feb 7 17:19:33 GMT 2023
On 2023-02-07 05:07, Andrey Repin via Cygwin wrote:
> Greetings, All!
>
> In the attached script, that I always run using dash, the expansion is
> supposed to strip leading/trailing spaces from provided parameter.
>
> The upgrade that took place after which the expansion stopped working is
>
> libsolv: - dash-0.5.11.5-1.any -> dash-0.5.12-1.any
>
> Downgrading to 0.5.11.5 restored the expected behavior.
> I failed to find anything relevant in the dash 0.5.12 patch notes, but perhaps
> community could help?
Good catch Andrey,
Looks like something in dash broke space trimming of any sort: see attached
script and logs.
I will see what upstream has to say for themselves, or about Cygwin.
[and stop apologizing for your terrible English, it's better than most, and much
better than most of our Russian, but we are ni kulturni, da? I kept missing out
on new language classes because teachers got transferred: no Russian at 11, no
Spanish at 17, or I could be kulturni!] ;^>
--
Take care. Thanks, Brian Inglis Calgary, Alberta, Canada
La perfection est atteinte Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer but when there is no more to cut
-- Antoine de Saint-Exupéry
-------------- next part --------------
#!/bin/dash -vx
trim() {
# remove leading whitespace characters
__trim="${*#${*%%[![:space:]]*}}"
# remove trailing whitespace characters
printf "%s" "${__trim%${__trim##*[![:space:]]}}"
}
trim " alpha" | od -t x1a
trim "beta " | od -t x1a
trim "
gamma " | od -t x1a
trim2() {
# remove leading whitespace characters
__trim="${*##[[:space:]]}"
# remove trailing whitespace characters
printf "%s" "${__trim%%[[:space:]]}"
}
trim2 " alpha" | od -t x1a
trim2 "beta " | od -t x1a
trim2 "
gamma " | od -t x1a
trim3() {
_space=$(echo -n '\b\t\n\v\f\r')
# remove leading whitespace characters
__trim="${*##$_space}"
# remove trailing whitespace characters
printf "%s" "${__trim%%$_space}"
}
trim2 " alpha" | od -t x1a
trim2 "beta " | od -t x1a
trim2 "
gamma " | od -t x1a
-------------- next part --------------
#!/bin/dash -vx
trim() {
# remove leading whitespace characters
__trim="${*#${*%%[![:space:]]*}}"
# remove trailing whitespace characters
printf "%s" "${__trim%${__trim##*[![:space:]]}}"
}
trim " alpha" | od -t x1a
+ trim alpha
+ __trim=alpha
+ printf %s alpha
+ od -t x1a
0000000 61 6c 70 68 61
a l p h a
0000005
trim "beta " | od -t x1a
+ trim beta
+ __trim=beta
+ printf %s beta
+ od -t x1a
0000000 62 65 74 61
b e t a
0000004
trim "
gamma " | od -t x1a
+ trim
gamma
+ __trim=gamma
+ printf %s gamma
+ od -t x1a
0000000 67 61 6d 6d 61
g a m m a
0000005
trim2() {
# remove leading whitespace characters
__trim="${*##[[:space:]]}"
# remove trailing whitespace characters
printf "%s" "${__trim%%[[:space:]]}"
}
trim2 " alpha" | od -t x1a
+ trim2 alpha
+ __trim=alpha
+ printf %s alpha
+ od -t x1a
0000000 61 6c 70 68 61
a l p h a
0000005
trim2 "beta " | od -t x1a
+ trim2 beta
+ __trim=beta
+ printf %s beta
+ od -t x1a
0000000 62 65 74 61
b e t a
0000004
trim2 "
gamma " | od -t x1a
+ trim2
gamma
+ __trim=gamma
+ printf %s gamma
+ od -t x1a
0000000 67 61 6d 6d 61
g a m m a
0000005
trim3() {
_space=$(echo -n '\b\t\n\v\f\r')
# remove leading whitespace characters
__trim="${*##$_space}"
# remove trailing whitespace characters
printf "%s" "${__trim%%$_space}"
}
trim2 " alpha" | od -t x1a
+ trim2 alpha
+ __trim=alpha
+ printf %s alpha
+ od -t x1a
0000000 61 6c 70 68 61
a l p h a
0000005
trim2 "beta " | od -t x1a
+ trim2 beta
+ __trim=beta
+ printf %s beta
+ od -t x1a
0000000 62 65 74 61
b e t a
0000004
trim2 "
gamma " | od -t x1a
+ trim2
gamma
+ __trim=gamma
+ printf %s gamma
+ od -t x1a
0000000 67 61 6d 6d 61
g a m m a
0000005
-------------- next part --------------
#!/bin/dash -vx
trim() {
# remove leading whitespace characters
__trim="${*#${*%%[![:space:]]*}}"
# remove trailing whitespace characters
printf "%s" "${__trim%${__trim##*[![:space:]]}}"
}
trim " alpha" | od -t x1a
+ trim alpha
+ __trim=
+ printf %s
+ od -t x1a
0000000
trim "beta " | od -t x1a
+ trim beta
+ __trim=
+ printf %s
+ od -t x1a
0000000
trim "
gamma " | od -t x1a
+ trim
gamma
+ __trim=
+ printf %s
+ od -t x1a
0000000
trim2() {
# remove leading whitespace characters
__trim="${*##[[:space:]]}"
# remove trailing whitespace characters
printf "%s" "${__trim%%[[:space:]]}"
}
trim2 " alpha" | od -t x1a
+ trim2 alpha
+ __trim= alpha
+ printf %s alpha
+ od -t x1a
0000000 20 61 6c 70 68 61
sp a l p h a
0000006
trim2 "beta " | od -t x1a
+ trim2 beta
+ __trim=beta
+ printf %s beta
+ od -t x1a
0000000 62 65 74 61 20
b e t a sp
0000005
trim2 "
gamma " | od -t x1a
+ trim2
gamma
+ __trim=
gamma
+ printf %s
gamma
+ od -t x1a
0000000 0d 67 61 6d 6d 61 09
cr g a m m a ht
0000007
trim3() {
_space=$(echo -n '\b\t\n\v\f\r')
# remove leading whitespace characters
__trim="${*##$_space}"
# remove trailing whitespace characters
printf "%s" "${__trim%%$_space}"
}
trim2 " alpha" | od -t x1a
+ trim2 alpha
+ __trim= alpha
+ printf %s alpha
+ od -t x1a
0000000 20 61 6c 70 68 61
sp a l p h a
0000006
trim2 "beta " | od -t x1a
+ trim2 beta
+ __trim=beta
+ printf %s beta
+ od -t x1a
0000000 62 65 74 61 20
b e t a sp
0000005
trim2 "
gamma " | od -t x1a
+ trim2
gamma
+ __trim=
gamma
+ printf %s
gamma
+ od -t x1a
0000000 0d 67 61 6d 6d 61 09
cr g a m m a ht
0000007
More information about the Cygwin
mailing list