Shellowa zagadka

Kacper Kornet kornet at camk.edu.pl
Fri May 6 14:27:04 CEST 2011


On Thu, May 05, 2011 at 08:48:50PM +0200, Przemyslaw Iskra wrote:
> On Thu, May 05, 2011 at 08:29:11PM +0200, Kacper Kornet wrote:
> > Przy okazji wyjścia nowej wersji git'a trafiłem na następującą zagwozdkę
> > na naszym /bin/sh. Otóż skrypt:

> > x=2; unset a; echo "${a:-'$x'}"

> > zwraca:

> > $x

> > Natomiast bash, zsh, dash i ash zwracają '2' w tym wypadku. Pytanie do
> > znawców: co jest poprawne z punktu widzenia POSIX.

> Nie opisane.

> http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02


> If a parameter expansion occurs inside double-quotes:

> * Pathname expansion shall not be performed on the results of the expansion.
> * Field splitting shall not be performed on the results of the
>   expansion, with the exception of '@'

Googlanie wskazuje, że większość ludzi uważa, że pdksh się tu jednak
myli. Np. mksh, które się mieni kontynuatorem pdksh ma przy najnowszej
wersji taki dopisek:

R39c: Evaluation of things like ${foo:-bar} and "${foo+bar}" now behave
standards-compliant (SUSv4) and more like all other shells, sans bugs.
In particular, if a ${} expression is double-quoted, the
apostrophe/single quote loses its special meaning within, whereas it
still acts as quote character if the expression is not double quoted.
Other special characters' meanings have been updated to match
standardised/expected behaviour.

> Lepiej unikać ${nazwa:COŚTAM} wewnątrz "" i tyle.

A to pewnie racja.

-- 
  Kacper 


More information about the pld-devel-pl mailing list