Prev: copy a filesystem and preserve hard links on Linux
Next: awk: use { or } as the field-separator.
From: Roman Cheplyaka on 20 Feb 2010 09:05 I'm interested in construction like ${x:-} Is it a correct shell token? Judging from this document http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html section 2.6.2 this is not correct since the word after ":-" is not optional. (Compare with ":?" where the word is optional.) But shell implementations available to me (bash,dash,zsh) all accept it. Do they get it wrong?
From: Janis Papanagnou on 20 Feb 2010 10:01 Roman Cheplyaka wrote: > I'm interested in construction like > ${x:-} > Is it a correct shell token? Yes, I'd say; a word can be empty, as it is maybe more apparent in the simple assignment var=word where you can omit the word as well. > Judging from this document http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html > section 2.6.2 this is not correct since the word after ":-" is not > optional. (Compare with ":?" where the word is optional.) The latter is a different case; if you omit the word some predefined message will be printed, i.e. you have a different operational semantic if you compare the two cases, with and without word. Probably that was the intention to mark the word optional in the POSIX syntax description. If you have a look into the respective syntax description of ksh, e.g., you won't even find that word marked optional. And the shells as well behave differently[*]. > But shell implementations available to me (bash,dash,zsh) all accept (and ksh) > it. Do they get it wrong? This one they've got right. :-) Janis [*] WRT ${var:?word} compare the results from different SHELLs if executing unset x ; y="" SHELL -c 'echo ${x:?"huh"}' SHELL -c 'echo ${x:?"$y"}' SHELL -c 'echo ${x:?""}' SHELL -c 'echo ${x:?}' = ksh = ksh: line 1: x: huh ksh: line 1: x: parameter not set ksh: line 1: x: parameter not set ksh: line 1: x: parameter not set = bash = bash: x: huh bash: x: bash: x: bash: x: parameter null or not set = zsh = zsh: x: huh zsh: x: $y zsh: x: zsh: x: parameter not set = ash = huh x: parameter null or not set x: parameter null or not set No two shells with the same behaviour. Janis
From: William Ahern on 20 Feb 2010 12:49 Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote: > Roman Cheplyaka wrote: > > I'm interested in construction like > > ${x:-} > > Is it a correct shell token? It should be, as should ${x-}. The latter is especially handy when one does `set -u` but explicitly desires empty expansion for some particular, possibly unset variable.
From: Mark Hobley on 21 Feb 2010 03:08 Kaz Kylheku <kkylheku(a)gmail.com> wrote: I don't think 3.435 makes this any clearer. It would have been much better to state that "word may be an empty string and can be omitted". Mark. -- Mark Hobley Linux User: #370818 http://markhobley.yi.org/
From: Sven Mascheck on 25 Feb 2010 18:57 Janis Papanagnou wrote: > No two shells with the same behaviour. And, sort of anecdote, a case outrunning them all: pre-SVR3 Bourne shells even show different results depending on whether quotes are used or not, $ echo ${var?x} var: x $ echo ${var?"x"} var: � because the internal quoting mechanism uses the 8th bit and a bug reveals this in the above.
|
Pages: 1 Prev: copy a filesystem and preserve hard links on Linux Next: awk: use { or } as the field-separator. |