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] ... ]
link|improve this question

feedback

1 Answer

up vote 5 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 -.

link|improve this answer
Wow, that was quick. Thanks a bunch. Seems to work like a charm. – STATUS_ACCESS_DENIED Feb 6 at 17:21
feedback

Your Answer

 
or
required, but never shown

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