ksh
su
別のユーザーに切り替えてコマンドを実行するルートでスクリプトを実行しています。しかし、何らかの理由で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