EOF를 사용하여 사용자를 전환하는 것이 작동하지 않습니다. su - ${instance} <<'EOF'

EOF를 사용하여 사용자를 전환하는 것이 작동하지 않습니다. su - ${instance} <<'EOF'

kshsu다른 사용자로 전환()하고 명령을 실행하는 루트에서 스크립트를 실행 중입니다 . 그러나 어떤 이유로 EOF는 그렇지 않습니다. 이것은 내 코드의 일부입니다.

코드의 이 부분은 작동하지 않습니다 su - $instance <<'EOF'. 통과하지 못합니다.$instance

instgroup=`id $instance | awk {'print $2'} | sed 's/[^ ]*( *//' | sed 's/.$//'`
db2instance=`ps -eaf | grep db2sysc |grep -v grep | awk '{print $1}' | sort
for instance in ${db2instance}; do
     echo "$instance"
     su - $instance <<'EOF'
     echo "user -" ${instance}
     echo "Checking all DB paths for Databases in $instance"
     echo ""
     $HOME/sqllib/db2profile
     for dbname in `db2 list db directory | grep -p Indirect | grep alias | awk '{print $NF}'`
     do
       echo "...."
     done
  EOF
done

답변1

작은따옴표 구분 기호는 문자열 리터럴로 처리됩니다. 이 예를 고려해보세요.

hw='hello world'

echo 'Attempt 1'
nl <<EOF
Good morning
My phrase today is $hw
That is all
EOF

echo 'Attempt 2'
nl <<'EOF'
Good morning
My phrase today is $hw
That is all
EOF

산출

Attempt 1
     1  Good morning
     2  My phrase today is hello world
     3  That is all
Attempt 2
     1  Good morning
     2  My phrase today is $hw
     3  That is all

관련 정보