Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15234
| From | Léa Gris <lea.gris@noiraude.net> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Explicit variables declaration statements do not resolve back-references from same statement |
| Date | 2019-07-24 20:01 +0200 |
| Message-ID | <mailman.2159.1563991303.2688.bug-bash@gnu.org> (permalink) |
| References | <fa53376b-927b-a37b-bb4d-ff0ebd7e25bf@noiraude.net> |
[Multipart message — attachments visible in raw view] - view raw
Found this strange behavior difference in Bash, between explicit and
implicit declarations of variables.
An implicit variables declaration statement resolve back-references to
variables from the same statement.
Whereas:
An explicit variables declaration statement does not resolve
back-reference variables from the same statement.
Illustration code:
==== knip code start
#!/usr/bin/env bash
unset a b c
printf $'\nExplicit declarations statements:\n'
printf $'\ntypeset -i a=2 b=$a c="$((a - 1))":\n=> '
typeset -i a=2 b=$a c="$((a - 1))"
printf 'a=%d b=%d c=%d\n' "${a}" "${b}" "${c}"
unset a b c
printf $'\ndeclare a=hello b=world c="$a $b":\n=> '
declare a='hello' b='world' c="${a} ${b}"
printf $"a='%s' b='%s' c='%s'\\n" "${a}" "${b}" "${c}"
unset a b c
printf $'\nImplicit declarations statements:\n'
a=2 b=$a c="$((a - 1))"
printf $'\na=2 b=$a c="$((a - 1))":\n=> '
printf 'a=%d b=%d c=%d\n' "${a}" "${b}" "${c}"
unset a b c
a='hello' b='world' c="${a} ${b}"
printf $'\na=hello b=world c="$a $b":\n=> '
printf $"a='%s' b='%s' c='%s'\\n" "$a" "$b" "$c"
==== knip code end
Output:
> Explicit declarations statements:
>
> typeset -i a=2 b=$a c="$((a - 1))":
> => a=2 b=2 c=1
>
> declare a=hello b=world c="$a $b":
> => ./b.sh[10]: declare: not found [Aucun fichier ou dossier de ce type]
> a='' b='' c=''
>
> Implicit declarations statements:
>
> a=2 b=$a c="$((a - 1))":
> => a=2 b=2 c=1
>
> a=hello b=world c="$a $b":
> => a='hello' b='world' c='hello world'
ksh93 resolves explicit back-references with typeset.
--
Léa Gris
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Explicit variables declaration statements do not resolve back-references from same statement Léa Gris <lea.gris@noiraude.net> - 2019-07-24 20:01 +0200
csiph-web