Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I incorrectly declared a variable, and now it has two forward slashes in it. How do I unset/correct it?

PATH=...ols-1.3-62308//bin:/bin

Thanks.

share|improve this question
    
export PATH="stuff" ? –  karthick87 Dec 29 '10 at 6:54
    
Please note that variable values changed dynamically are lost once you exit the current shell right. If you need them to be persistent you will need to update your bash profile. –  João Pinto Dec 29 '10 at 10:17
add comment

3 Answers

up vote 2 down vote accepted

In this particular example, do nothing: the double slash is exactly equivalent to a single slash.

If you really want to remove double slashes: PATH=${PATH//\/\//\/}

Removing the first entry: PATH=${PATH#*:}
Removing the last entry: PATH=${PATH%:*}
Removing an entry from the middle is more fiddly, and not really worth it on the command line.

There are ways to get the value of a variable into the command line editor:

  • In zsh, you would simply run vared PATH.
  • In bash, run history -s "PATH=$PATH" to push the assignment into the command history, then press Up to bring up the last entry and edit it. (Zsh: print -s PATH=$PATH)
  • In bash, type PATH=$PATH, then press Ctrl+Meta+E (shell-expand-line). (Zsh: press Ctrl+X * to expand the word at or before the cursor.)
share|improve this answer
add comment

You will want to include the $PATH

if you're using bash you usually want to set something like the line below in your .bashrc file:

PATH=$PATH:/path/to/new/directory/

ie. $PATH is your currnet PATH

and /path/to/new/directory is the path where the new binaries are stored.

in my case I tend to have some scripts in my $HOME/bin so I would do: PATH=$PATH:$HOME/bin

then make sure to source the file to apply the changes to your current shell.

ie. source ~/.bashrc or . ~/.bashrc

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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