Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I create an alias named - in Bash? None of the following works:

alias -='cd -'
alias \-='cd -'
alias '-'='cd -'

with error:

bash: alias: -=: invalid option
alias: usage: alias [-p] [name[=value] ... ]
share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Use the following:

alias -- -='cd -'

-- is often used (especially with Gnu programs) to stop parsing the following arguments as options. That's also how you can e.g. rm files whose names start with -.

share|improve this answer
    
Wow, that was quick. Thanks a bunch. Seems to work like a charm. –  0xC0000022L Feb 6 '12 at 17:21
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.