0

I am running a ksh script from root where I switch (su) to different users and execute the commands. But, some reason EOF does not. Here is part of my code.

This part of the code does not work su - $instance <<'EOF': it does not pass the $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
Chris Davies
  • 116,213
  • 16
  • 160
  • 287

1 Answers1

2

A single-quoted heredoc is treated as a string literal. Consider this example,

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

Output

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
Chris Davies
  • 116,213
  • 16
  • 160
  • 287