Douglas Reid
Douglas Reid

Reputation: 3788

Is there a concise way to define two or more bash aliases for the same expansion?

Suppose I want to use both e and c as quick ways to open the current folder in my preferred editor.

Do I need to define my bash aliases like this:

alias c="code ."
alias e="code ."

Or is there a more concise syntax? Something like this (which I tried, but it did not work):

alias c,e="code ."

I've also not found a concise alternative by searching guides, the web, and the bash alias questions here. Still, it's hard to prove a negative. :-)


Note: I am specifically using git-bash. I anticpate any answer would apply to bash more generally.

Upvotes: 0

Views: 139

Answers (2)

Douglas Reid
Douglas Reid

Reputation: 3788

While I prefer the accepted answer a workable alternative is to expand the second (third..n) alias(es) into the first, instead of repeating the expansion.

alias c="code ."
alias e=c

Upvotes: 0

Charles Duffy
Charles Duffy

Reputation: 295443

alias {c,e}="code ."

...will, after brace expansion, become:

alias c="code ." e="code ."

...which does what you want.


That said, I don't believe this question is on-topic here; aliases are an interactive facility not available by default in scripts, and Stack Overflow is exclusively scoped to software development. Writing scripts definitely counts; using your command-line shell, not so much.

Upvotes: 6

Related Questions