I have a bash script/s which has a "main" script which is run as sudo
.
Variables are declared in this script.
Then it sources another commands.sh
script, however this script uses sudo
to drop back to an ordinary user when sourcing the commands.sh
script.
file: main.sh
#!/bin/bash
user=ubuntu
export $user
sudo -u $user bash -c "source includes-shared/commands.sh"
file: includes-shared/commands.sh
# debug command to see if $user is available
printenv
[ more commands...]
The variable $user
no longer appears in this commands.sh
script, i.e. it is not visible to printenv
or other commands.
How can I export $user
so that it is available to the sourced script?