I am trying to add some exports using the following method:

sudo bash -c "cat >> /etc/bash.bashrc" <<'EOF'
export AWS_CONFIG_FILE=/etc/test/aws.txt
export PATH="$PATH:/usr/local/bin/"

I have two questions:

  1. For what ever reason, it simply isn't working, the config isnt being read by AWS as if it was never linked. Have I done this correctly?

  2. Secondly, does this survive a reboot? As in, will I just have to do it once, and when I reboot the server it will still be there, or instead will I have to add these commands to my rc.local so they are reinstated on every reboot of the server.

Thank you for any help you can give.


It isn't clear from your question exactly where and when you are running the scriptlet that you presented.

After you run the scriptlet do cat /etc/bash.bashrc to see if the two export lines are there.

The scriptlet adds two lines to /etc/bash.bashrc each time it runs. If you run it twice then you will have duplicate lines. The file /etc/bash.bashrc is a regular configuration file, not regenerated every boot, so any changes you make are persistent. So, you probably only want to run this script once on each platform you install it on.

In any event, /etc/bash.bashrc is probably not a good place to put global additions to PATH. You put those in /etc/profile. But before you do that, do echo $PATH to verify that /usr/local/bin isn't already there. In most distributions it is included in the PATH out-of-the-box.

Changes that you make to /etc/bash.bashrc will be effective for new bash processes such as terminal windows running bash that you start after you make the change. The change does not effect currently running windows.

The PATH environment variable that you set in /etc/profile of in a .bashrc file affects only bash shells. If you start a program from crontab, at or from an /etc/rc.d file, then you need to set the PATH specifically in those scripts, or use the etc/environment file to set environment variables for all processes. See this link that explains the differences.


System-wide environment variables can be placed in /etc/environment.

Once you added the lines you mentioned to /etc/bash.bashrc, every bash process should 'know' them. You can verify this, with:

echo $PATH


source /etc/bash.bashrc
echo $PATH

Also check out the Ubuntu Community Wiki on Environment Variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.