In my script, I try to source two files to fetch the variables.
But it failed to get the variables defined in ~/.bashrc.
OS: Ubuntu Desktop 20.04.2 LTS
$ cat debug.sh
#!/usr/bin/env bash
cat > ~/env.sh << EOF
VAR1="123"
EOF
echo "VAR2=456" >> ~/.bashrc
source ~/env.sh
source ~/.bashrc
set -u
echo ${VAR1}
echo ${VAR2}
$ ./debug.sh
123
./debug.sh: line 14: VAR2: unbound variable
~/.bashrc?.bashrc-- bad idea...) Use a temporary file instead.sourcewith.to source the file inside the script...example:. ~/.env.sh.bashrcas a common library. Its purpose is to configure an interactive shell. If there is code you want in both a script and in an interactive shell, put that in a 3rd file and source it from both.bashrcand your script.