Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15234 > unrolled thread
| Started by | Léa Gris <lea.gris@noiraude.net> |
|---|---|
| First post | 2019-07-24 20:01 +0200 |
| Last post | 2019-07-24 20:01 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Léa Gris <lea.gris@noiraude.net> |
|---|---|
| Date | 2019-07-24 20:01 +0200 |
| Subject | Explicit variables declaration statements do not resolve back-references from same statement |
| Message-ID | <mailman.2159.1563991303.2688.bug-bash@gnu.org> |
[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 top | Article view | gnu.bash.bug
csiph-web