bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Parameter Expansion] bug in ${variable% *}


From: Bernd Eggink
Subject: Re: [Parameter Expansion] bug in ${variable% *}
Date: Tue, 12 Feb 2013 10:13:46 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 11.02.2013 18:50, Dashing wrote:
Bash version: 4.2.042

I have a script that behaves erratically:
=========
#! /bin/bash
last=${1##* }
rest=${1% *}
while [[ "${rest: -1}" == '\' ]]; do
        last="${rest##* } $last"
        oldrest=$rest
        rest=${rest% *}
        if [[ "$oldrest" == "$rest" ]]; then
                echo :--Mistake--:
#               sleep 0.01
#               rest=${rest% *}
#               if [[ "$oldrest" == "$rest" ]]; then
#                       echo 'unable to interpret'
#                       break
#               fi
        fi
done
echo REST:$rest:
echo LAST:$last:
=========
$ ./pe 'mplayer foo1\ foo2\ foo3\ 4\ 5\ foo6\ 7'
:--Mistake--:
:--Mistake--:
REST:mplayer:
LAST:foo1\ foo1\ foo1\ foo2\ foo3\ 4\ 5\ foo6\ 7:
=========

What happens is that rest=${rest% *} doesn't always update $rest,
even when there are spaces left in $rest.
Meanwhile last="${rest##* } $last" works every time.
In the above example it got stuck twice when $rest was mplayer
foo1\. It tends to vary wildly.

The script runs fine if you omit the superfluous blank in the ${rest: -1} expression:

        while [[ "${rest:-1}" == '\' ]]; do

If the script behaves indeterministic, it is probably a bash bug.

Regards,
Bernd



--
www.sudrala.de


reply via email to

[Prev in Thread] Current Thread [Next in Thread]