ubuntu 18.04 I need to get the value of the last command executed in an at heredoc :
test.at.sh
#!/bin/bash
at now <<EOF
ls -la >> test.log;
RET=$?;
echo -e "\n----" >> test.log;
echo "exit code $RET" >> test.log;
EOF
I get in test.log only "exit code"
Even if I use bash inside at heredoc it doesn't work
test.at.sh
#!/bin/bash
at now <<EOF
/bin/bash -c '
ls -la >> test.log;
RET=$?;
echo -e "\n----" >> test.log;
echo "exit code $RET" >> test.log;
'
EOF
Strangely enough this works, I get in test.log "exit code 0" :
test.at.sh
#!/bin/bash
at now <<EOF
ls -la >> test.log;
echo "exit code $?" >> test.log;
EOF
This works ok
test.sh
#!/bin/bash
ls -la >> test.log;
RET=$?;
echo -e "\n----" >> test.log;
echo "exit code $RET" >> test.log;
I get in test.log "exit code 0"
Any ideas? Thanks