Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I export PATH twice in .bashrc?

I'm running Ubuntu 12.04 and trying to be ale to use both the Heroku CLI as well as the newly-downloaded AWS Elastic Beanstalk CLI tools.

I have this code in my .bashrc already:

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"

And I also want to export this:

#for Elastic Beanstalk - madebyian
export PATH=$PATH:/opt/AWS-ElasticBeanstalk-CLI-2.6.0/eb/linux/python3/

How do I get both CLI tools and/or what's wrong with my syntax EDIT:[if anything]?

like image 340
ionox0 Avatar asked Mar 20 '14 01:03

ionox0


People also ask

What is the rule for using export in bashrc?

I am wondering if, first, this is correct, and second what the rule is for using export in .bashrc. You only need export for variables that should be "seen" by other programs which you launch in the shell, while the ones that are only used inside the shell itself don't need to be export ed.

What is the difference between export and path in Bash?

The PATH variable lets bash know where to look for executable programs, so if you have a script or some other executable file in $HOME/.local/bin , modifying PATH will let you type and run that file just like you do with ls or df. export only means to make that PATH variable also available for other programs you run from bash.

Why is my bashrc not being read by the interactive shell?

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. So if your shell is a login shell, ~/.bashrc is not read. I would put additions to PATH in ~/.bash_profile instead, and/or possibly source ~/.bashrc from there.

How to open bashrc file in Ubuntu 20 04?

The bashrc file of a Ubuntu 20.04 system can be accessed by executing the command shown below: The command mentioned in the second step will open the bashrc file of your Ubuntu 20.04 system with the nano editor. Once this file opens up, you need to scroll down to the end of the file and then add the subsequent line to it:


1 Answers

You can export it as many times as you want, it will make no difference (after the first export, obviously).

All export does in this context (other than changing the variable itself due to the =) is mark a variable so that it's exported to the environment of future commands.

You can mark it so as much as you want. The effect of the two commands:

export PATH="/usr/local/heroku/bin:$PATH"
export PATH=$PATH:/opt/AWS-ElasticBeanstalk-CLI-2.6.0/eb/linux/python3/

will be to mark PATH as an export variable (it probably is so already since you generally want your path to be inherited) and set it to:

/usr/local/heroku/bin:$PATH:/opt/AWS-ElasticBeanstalk-CLI-2.6.0/eb/linux/python3/

where $PATH was the path before executing those commands.

The only thing you need to be careful of is the ordering. For example, if /usr/local/heroku/bin contains an executable program called ls, that's probably going to make life difficult for you if you're trying to get a directory listing. For that reason, I tend to add directories only to the end of the path.

Alternatively, you can make the order less permanent by providing an alias or function which changes your path to the Heroku-preferred one only for the current session.


Keep in mind that the files that get run by bash are a complex matter. .bashrc is run for interactive, non-login shells so may not run in all cases (I, for one, fix that by calling .bashrc at the end of my .bash_profile though some people may cringe at that).

You're probably better off setting (and exporting) the path in your .bash_profile.


And, if there is something wrong with what you're doing (your syntax seems fine but there may be other problems we cannot discern due to lack of information), you should perform the following steps:

  • echo $PATH before and after each export command to see if something is stuffing it up.
  • ensure that each component in the path actually exists (i.e., that you have the correct directories in there).
like image 199
paxdiablo Avatar answered Sep 24 '22 12:09

paxdiablo