Super User is a question and answer site for computer enthusiasts and power users. 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 want to map the - to cd -

I've tried escaping it, w/ and w/o single/double quotes but neither of them seems to work.

alias \-='cd -' or alias '-'='cd -' =>
bash: alias: -=: invalid option alias: usage: alias [-p] [name[=value] ... ]

So the problem is that bash thinks I want to define an option for alias. (What would be a | Is there any) workaround for this?

share|improve this question
up vote 6 down vote accepted

You must tell the alias command that you are not using - to specify an option. You do this by using -- to indicate end of options, any following text is then treated as arguments to the command.

  alias -- -=cd
share|improve this answer
1  
Also note that this is a common syntax for many GNU utilities: -- terminates parameter processing, treating the rest as file names to be operated on. – Michael Kjörling Dec 6 '12 at 10:28
    
I'm using - to popd, it works for me! – Marslo Mar 3 '14 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .