Jump to content
viking777

Changing PATH variable

Recommended Posts

If I type:

 

echo $PATH

 

as user I get:

 

 

/bin /usr/bin /usr/local/bin /usr/games /usr/lib/qt4/bin /usr/bin /opt/kde3/bin

 

I then type:

 

 export PATH=$PATH:/opt

 

and I get:

 

Unknown command “exportâ€

 

If I su to root and run:

 

 export PATH=$PATH:/opt

 

that is accepted but it changes roots PATH not mine.

 

How in hell do I change my user PATH variable to include /opt???

 

NB I only want to do it on a per session basis not permanently.

Share this post


Link to post
Share on other sites

Forget it, it is because I was using Fish. When I changed the shell back to bash it worked. But if anyone can tell me how to make it work in Fish I would love to know. It is a more 'friendly' shell.

 

Edit: apart from this problem obviously.

Edited by viking777

Share this post


Link to post
Share on other sites

Yeah, using "set" for (environment) variables is quite common in shells other than bash.

Guess it should be this way:

 

set -x PATH $PATH:/opt

Share this post


Link to post
Share on other sites
Yeah, using "set" for (environment) variables is quite common in shells other than bash.
I never got why it was "export" - every time I used it, I always thought, "where am I exporting this variable to? Am I not just setting it?" :unsure:

 

set makes much more sense.

Edited by tyme

Share this post


Link to post
Share on other sites
Yeah, using "set" for (environment) variables is quite common in shells other than bash.

Guess it should be this way:

 

set -x PATH $PATH:/opt

 

scoonma, since you are the one who told me about this (and I thank you again) it seems pretty churlish of me to go correcting you, so I apologise in advance. But I tried your command and it didn't work, a little bit of digging and I found the answer. This is what you need (in the fish shell anyway):

 

set PATH[7] /opt

 

This command will set /opt as the 7th entry in your environment variable PATH.

 

It does seem to be a lot easier than the 'export' command in bash.

Share this post


Link to post
Share on other sites
set PATH[7] /opt

 

This command will set /opt as the 7th entry in your environment variable PATH.

 

It does seem to be a lot easier than the 'export' command in bash.

But what's it do if you have 8 entry's in PATH already? Does it overwrite #7, or does it shift 7 to 8 and 8 to 9, then put the new one in 7? There has to be a way to do it that doesn't risk overwriting existing PATH entries.

Share this post


Link to post
Share on other sites

It doesn't over write anything, it just moves other entries along. I know, I used that command myself (and I have more than 7 entries).

 

But if it really worries you then count how many entries you have to start with and put it at the end.

Share this post


Link to post
Share on other sites
scoonma, since you are the one who told me about this (and I thank you again) it seems pretty churlish of me to go correcting you, so I apologise in advance. But I tried your command and it didn't work, a little bit of digging and I found the answer.

 

In fact I have to admit that I don't use fish myself, but found a linke to some useful docs. Another version is here:

Fish user docs

 

I supposed you needed the export of your path variable:

 

"Exporting variables

 

Variables in fish can be exported. This means the variable will be inherited by any commands started by fish. It is convention that exported variables are in uppercase and unexported variables are in lowercase."

Share this post


Link to post
Share on other sites
I believe you need to use "set", though I'm not versed in it's syntax:

http://www.fishshell.org/user_doc/commands.html#set

In fact I have to admit that I don't use fish myself, but found a linke to some useful docs. Another version is here:

Fish user docs

 

I supposed you needed the export of your path variable:

 

"Exporting variables

 

Variables in fish can be exported. This means the variable will be inherited by any commands started by fish. It is convention that exported variables are in uppercase and unexported variables are in lowercase."

:blink:

Edited by tyme

Share this post


Link to post
Share on other sites

Tyme,

 

I am not sure if your post was meant for me or scoonma. In case it was for me can I tell you I gave up on this a while back. Setting/Exporting variables in Fish was something I wanted to do once only, never before and never again after. What ever I did at the time worked for me but I don't really want to go back there!

 

Hell, I don't even like the command line. I ony started using Fish because I thought it might make cli a bit easier than bash - and it does to some extent, but not enough to make me want to use it too often!

 

Thanks for the post anyway.

Share this post


Link to post
Share on other sites

The post was simply meant to point out that I had already referred to the documents and details that scoonma posted, that's all.... :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...