ksh
我正在从 root运行一个脚本,在其中我切换 ( 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