I want my cron scripts being executed verbosly when run interactively by a system user (for debug purpose for instance) and quietly otherwise (for cron, as I want receive e-mail if and only if I get errors).
I have tried this in my script:
case "$-" in
*i*) echo "this shell is interactive" > /tmp/log;
*) echo "this shell isn't" > /tmp/log;
esac
but even when run interactively (/bin/bash /tmp/my_script.sh) it returns always "this shell isn't" and
echo $-
in shell script returns hB and not hiB.
I have also tried
if [ -z $PS1 ]
thinking that cron does not have $PS1 set, but once again, from prompt, echo $PS1 returns this variable, and interactively in a script, it returns nothing :/
I would like to know why interactively (/bin/bash my_script.sh) this does not return the i value for $- nor the value of $PS1.
Many thanks for your help!