3

I want to create two different aliases to the same command without repeating myself. How can I do it in bash? For example, I want listlong and longlist to both be aliases to "ls -al".

9
alias {listlong,longlist}="ls -al"

That should do it.

5
alias listlong='ls -al'
alias longlist=listlong

And further changes of the alias listlong reflect on longlist too.

  • I prefer this method because it requires less understanding of bash :-) – Torben Gundtofte-Bruun Sep 7 '10 at 13:32
2

Here's a variation on cYrus's answer with even less repetition:

alias listlong='ls -al' longlist=listlong

If you want to do something similar but have them be independent:

cmd='ls -al'; alias listlong=$cmd longlist=$cmd

which has similar results to Janne Pikkarainen's answer (which is the least repetitive so far).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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