I found an unexpected behavior in a bash script recently and I'd like to understand it before I work around it. Here's a simplified example:
#! /bin/sh
SCRIPT="/tmp/echoscript.sh >> /tmp/log"
/bin/sh ${SCRIPT}
echoscript.sh just does 'echo "abc"'
The unexpected thing is that 'abc' goes to the terminal and not to the /tmp/log file. Why is that?
If I change the third line to:
/bin/sh ${SCRIPT} >> /tmp/log
Then I get the expected result; 'abc' goes to the log file.