bug-bash
[Top][All Lists]
Advanced

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

Re: quoted and concatenated positional parameters


From: Dan Douglas
Subject: Re: quoted and concatenated positional parameters
Date: Thu, 24 May 2012 00:33:48 -0500
User-agent: KMail/4.8.3 (Linux/3.3.6-pf+; KDE/4.8.3; x86_64; ; )

On Wednesday, May 23, 2012 09:47:33 PM gregrwm wrote:
> expansion anomaly with quoted and concatenated positional parameters

Also reproducible in 4.2.28(1)-release

This occurs when any expansion is adjacent to or contained within a word that
is adjacent to an expansion of the from "$@" or "address@hidden", and within 
the same
double-quotes. Bash mistakenly treats "address@hidden" and "address@hidden""$x" 
differently.

> echo  '${@:2}c$1 c2 c3     #works as long as quoting omitted'

Because you're applying word-splitting to the result.  You'll see that there is
only one word if IFS is set to null.  It's impossible to test whether the
unquoted case is correct. The manpage says that only a quoted "$@" is split
into words for reasons other than word-splitting. Bash, mksh, and dash all
disagree about the unquoted cases, while Bash is the only shell to take issue
with the adjacent expansion in all cases.

 ~ $ for sh in {{,m}k,{d,b}a,z}sh; do printf '%s\n' "${sh}:" "$("$sh" -c 
"$(</dev/stdin)" -- {1..5})"; echo; done <<"EOF"                                
                                                                                
                           
args() { printf '<%s> ' "$@"; echo; }                                           
                                                                                
                                                                                
                                  
args "address@hidden"
args "address@hidden" 
args address@hidden                                                             
                                                                                
                                                                                
                                        
args address@hidden                                                             
                                                                                
                                                                                
                                         
IFS=                                                                            
                                                                                
                                                                                
                                  
args address@hidden                                                             
                                                                                
                                                                                
                                        
args address@hidden                                                             
                                                                                
                                                                                
                                         
EOF                                                                             
                                                                                
                                                                                
                                  

ksh:
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 

mksh:
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1 2 3 4 51> 
<1 2 3 4 5foo> 

dash:
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<123451> 
<12345foo> 

bash:
<1 2 3 4 51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1 2 3 4 51> 
<1> <2> <3> <4> <5foo> 

zsh:
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
<1> <2> <3> <4> <51> 
<1> <2> <3> <4> <5foo> 
-- 
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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