Create an alias - in Bash?

2

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

0xC0000022L

Posted 2012-02-06T17:16:22.173

Reputation: 5 091

Answers

6

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

Daniel Beck

Posted 2012-02-06T17:16:22.173

Reputation: 98 421

Wow, that was quick. Thanks a bunch. Seems to work like a charm. – 0xC0000022L – 2012-02-06T17:21:32.697