Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a bash alias for the cd - command

Tags:

alias

bash

I'd like the create the alias -- for the bash cd - command. Searching to solve this problem, I found the advice to use this alias:

alias -- -="cd -"

However, that leads to the following error, as seen in this session snippet:

chris@DeathStar:~$ cd .vim
chris@DeathStar:~/.vim$ --
-bash: --: command not found
chris@DeathStar:~/.vim$ 

My bash --version:

GNU bash, version 4.2.39(2)-release (i386-apple-darwin12.2.1)
Copyright (C) 2011 Free Software Foundation, Inc.

Any ideas?

like image 643
Chris Avatar asked Feb 01 '26 08:02

Chris


1 Answers

The alias you created seems to be -, not --. If you want it to be --, you need to declare it as:

alias -- --="cd -"

You can always check the list of declared aliases in your shell session, by simply typing alias.

P.S.

The first -- sequence following the alias has nothing to do with the alias name, it's just needed in order for the alias command to not consider following parameters starting with a - as command options.

like image 147
Costi Ciudatu Avatar answered Feb 04 '26 00:02

Costi Ciudatu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!