Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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



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
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

There is a similar post on stackoverflow: What is the most elegant way to remove a path from the $PATH variable in Bash?. Just have a look.

share|improve this answer

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:


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

Your Answer


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.