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

Re: Autoconf build targets



On Mon, May 20, 2002 at 03:48:04PM -0400, Daniel Burrows wrote:
>   It seems that bash doesn't like $( ... ) with a "case" statement
> inside it, since the case statement requires a ).  Probably the solution
> is to convert the whole thing to s-expressions. *runs away quickly*

A simple but hackish workaround is using $(eval '...').

This does even preserve the environment.

>   More seriously, does anyone know what POSIX says should happen here?
> I've Cced the bash and ash maintainers in case they have suggestions.

From bash(1): 
      When using the $(command) form, all characters between the
      parentheses make up the command; none are treated specially.

which is ambiguous, because it could mean that the characters will be
treated "as if they were not in a $( ) environment", in which case the
case statement should work, or it could mean that they "are not treated
specially at all" and that the first closing bracket will end the
command substitiution. The former points to a bug in bash (not correctly
parsing the content of $( ), while the latter seems to be very
constraining (and would contradict the working of the eval trick,
because this only works for the power of the single ticks).

>   I've attached a trivial program that exhibits the problem -- it
> should do something utterly pointless in ash, and fail to compile in
> bash.

Calling this with "plok" as parameter will give an error in bash, but
not in ash:

param=$1

echo $( 
    case "$param" in
        plok) 
            echo "$param"
        ;;
    esac
)



Error:

david@diode:~/tmp$ bash ./test.sh plok
./test.sh: command substitution: line 3: syntax error near unexpected token `plok'
./test.sh: command substitution: line 3: `        plok'
plok
./test.sh: line 8: syntax error near unexpected token `;'
./test.sh: line 8: `        ;;'
david@diode:~/tmp$ ash ./test.sh plok
.plok.
david@diode:~/tmp$ 


>   One other note: if I backslash-escape the case statement's ")", bash
> likes the program and ash doesn't.

Since ash seems to parse on within the command substition this breaks
the syntax of the case statement. Bash on th other hand needs this to
correctly parse the whole statment. Hmmmm ... very confusing.




HTH, David
-- 
Signaturen sind wie Frauen. Man findet selten eine Vernuenftige
	-- gesehen in at.linux
Signaturen sind wie Frauen. Hat man einmal eine Vernuenftige gefunden
gibt man sie nicht wieder her.	-- Hubert Partl

Attachment: pgpKfOnKMKJZb.pgp
Description: PGP signature


Reply to: