How to create alias for – minus sign

aliasbashunix

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?

Best Answer

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