How does one for subshell expansion in heredoc for all command?
eg:
file=report_$(date +%Y%m%d)
cat <<EOF > $file
date
hostname
echo 'End of Report'
EOF
such that all the commands are evaluated?
I am aware
file=report_$(date +%Y%m%d)
cat <<EOF > $file
$(date))
$(hostname)
$(echo 'End of Report')
EOF
would work, but is there a way to specify subshell by default?
You could use sh (or bash) as the command instead of cat; that will actually run it as shell script:
sh <<EOF > $file
date
hostname
echo 'End of Report'
EOF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With