쉘 스크립트 질문이요

yaru22의 이미지

어떤 변수가 담고 있는 문자열이 가르키는 값을 알아보려면 어떻게 하죠?

저렇게 말로 하니 복잡하니깐 예를 들어볼께요

Agent5="Brian Park"

i=5

var="Agent$i"

이랬을 경우 echo $var 하면 Agent5 가 나오자나요

근데 var를 이용해서 Agent5 가 가르키는 값, 즉 "Brian Park" 을 출력 할 수는 없나요?

wariua의 이미지

man bash wrote:
...
Parameter Expansion
...
${parameter}
...
If the first character of parameter is an exclamation point, a level of variable indirectino is introduced. bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself.
...

따라서
echo ${!var}

가 되겠습니다.
----
$PWD `date`

$PWD `date`