2017-06-06 15 views
-1

私はこのフォーラムで初心者です 私はコードに沿って変数を動的に変更したいと考えています。 Ex。kshの動的割り当て

#!/bin/ksh -f 
VAR1=123456 
VAR2=$VAR1 
echo VAR1 # Will return '123456', good 
echo VAR2 # Will return '123456', good 
VAR1=azerty 
echo VAR2 # Will return 123456, not good, I hope it was 'azerty', the new value of VAR1 

誰もが事前にこの質問への答えやヒント

Thxをしている場合、 Antrema

答えて

0

のTry nameref、例えば:

$ VAR1=123456 
$ nameref VAR2=VAR1 
$ echo "$VAR1 : $VAR2" 

123456 : 123456 

$ VAR1=azerty 
$ echo "$VAR1 : $VAR2" 

azerty : azerty 

# NOTE: this relationship works in both directions, eg: 

$ VAR2=xyz123 
$ echo "$VAR1 : $VAR2" 

xyz123 : xyz123 

参照してください。O'Reilly: Learning the Korn Shell: 4.4 Indirect Variable References

関連する問題