title: How to `cat << 'EOF'` within `su $user <<EOF`?
body: <pre><code>##!/bin/bash
  set -e
  backup_dir='/home/my/backup'
  user='my'
  
  su $user &lt;&lt;EOFHD
  cat &lt;&lt; 'EOF' &gt; $backup_dir/autorestartnftables.sh
  #!/bin/bash
  SERVICENAME=&quot;nftables&quot;
  
  # return value is 0 if running
  STATUS=$?
  if [[ &quot;$STATUS&quot; -ne &quot;0&quot; ]]; then
          echo &quot;Service '$SERVICENAME' is not curently running... Starting now...&quot;
          systemctl start $SERVICENAME
  fi
  EOF
  chmod +x $backup_dir/autorestartnftables.sh
  EOFHD
  </code></pre>
  <p>Above script is used to create <code>autorestartnftables.sh</code>,expect result as below:</p>
  <pre><code>#!/bin/bash
  SERVICENAME=&quot;nftables&quot;
  # return value is 0 if running
  STATUS=$？
  if [[ &quot;$STATUS&quot; -ne &quot;0&quot; ]]; then
          echo &quot;Service '$SERVICENAME' is not curently running... Starting now...&quot;
          systemctl start $SERVICENAME
  fi
  </code></pre>
  <p><code>autorestartnftables.sh</code> after run <code>sudo bash ./example.sh</code>:</p>
  <pre><code>#!/bin/bash
  SERVICENAME=&quot;nftables&quot;
  # return value is 0 if running
  STATUS=0
  if [[ &quot;&quot; -ne &quot;0&quot; ]]; then
          echo &quot;Service '' is not curently running... Starting now...&quot;
          systemctl start 
  fi
  </code></pre>
  <p>Where is the problem?</p>