I have a script that requires the env variable USER to be set. As the script is used by several users, I can't just do export USER=xxx at the beginning of the script. I could define in the crontab, but I was just wondering whether there is a good way of pulling it in.
I tried sourcing .bashrc and .profile, but neither define USER, plus on Ubuntu .bashrc simply returns on non-interactive shells.
You could work around it by writing at the top of the script (Bashism):
USER=$(whoami)
or old-style:
USER=`whoami`
... assuming you have whoami in the PATH, which can also be set in the crontab just like several (most?) other variables. I.e. you can also set the variable in crontab itself (at least in Vixies cron) - see here for example.
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