<![CDATA[Forum Ubuntu-fr.org / [Bash] Point d'exclamation et variable]]> http://forum.ubuntu-fr.org/viewtopic.php?id=350532 Tue, 20 Oct 2009 08:56:24 +0000 FluxBB <![CDATA[Réponse à : [Bash] Point d'exclamation et variable]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=2996648#p2996648 Il s'agit d'un exemple de référencement indirect.
Tu trouveras des indications là-dessus dans l'excellentissime manuel de Cooper sur Bash.
Voir le site :
http://abs.traduc.org/abs-fr/ 
(lien vers une traduction en français du manuel, tu y trouveras aussi, vers le haut, dans la rubrique "Résumé", un lien
Version PDF
qui permet  d'obtenir la version anglaise  la plus récente du manuel de Cooper).

Cooper donne entre autres l'exemple de programme suivant pour éclaircir la notion :

#!/bin/bash
# Indirect variable referencing.
# This has a few of the attributes of references in C++.
a=letter_of_alphabet
letter_of_alphabet=z
echo "a = $a"             # Direct reference.
echo "Now a = ${!a}"      # Indirect reference.
# The ${!variable} notation is more intuitive than the old
#+ eval var1=\$$var2
echo

t=table_cell_3
table_cell_3=24
echo "t = ${!t}"                      # t = 24
table_cell_3=387
echo "Value of t changed to ${!t}"    # 387
# No 'eval' necessary.
#  This is useful for referencing members of an array or table,
#+ or for simulating a multi-dimensional array.
#  An indexing option (analogous to pointer arithmetic)
#+ would have been nice. Sigh.
exit 0
# See also, ind-ref.sh example.
]]>
Tue, 20 Oct 2009 08:56:24 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=2996648#p2996648
<![CDATA[Réponse à : [Bash] Point d'exclamation et variable]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=2996637#p2996637 Trouvé dans (l'excellent) bash avancé :

${!variable} Référence de variable indirecte

Ce qui veut dire que :

toto="salut la foule"
titi="toto"
echo ${!titi}

affichera "salut la foule".

]]>
Tue, 20 Oct 2009 08:49:32 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=2996637#p2996637
<![CDATA[Réponse à : [Bash] Point d'exclamation et variable]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=2996631#p2996631 Bonjour,

@peck : la syntaxe est bonne
@Geoffrey35 : c'est pour récupérer la valeur de la variable dont le nom est la valeur de la variable i

]]>
Tue, 20 Oct 2009 08:43:07 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=2996631#p2996631
<![CDATA[Réponse à : [Bash] Point d'exclamation et variable]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=2996543#p2996543 Tu es sur que c'est !i tout court et pas !i@ ou !i* ?
Car cela correspond à la découverte de variable dont le nom commence par i.

]]>
Tue, 20 Oct 2009 07:45:48 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=2996543#p2996543
<![CDATA[[Bash] Point d'exclamation et variable]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=2996527#p2996527 Bonjour,
Des fois dans des scripts je vois des trucs comme ca:
${!i}
Pourquoi, avec un point d'exclamation et pas
$(i) ou encore ${i}
Enfin vous l'aurez compris, pourquoi ce point d'exclamation?
Merci de vos réponses.

]]>
Tue, 20 Oct 2009 07:26:55 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=2996527#p2996527