I need to run a small shell script using C popen call (which calls sh -c '<command>'
). I can't get my script to work. I isolated the issue to this snippet:
#!/bin/bash
sh -c 'bash -xev -s << EOF
a=1
echo "a=$a"
EOF'
which outputs
a=1
+ a=1
echo "a="
+ echo a=
a=
What am I missing? Why can't I use variables from stdin?
(versions: GNU bash 5.1.4, dash 0.5.11+git20200708+dd9ef66-5)
\EOF
. Thank you very much. Will mark this answer. – ofo Feb 21 '21 at 21:44"EOF"
or'EOF'
– steeldriver Feb 21 '21 at 21:48