Create multiple shell aliases at once
The help for alias
indicates that it can assign multiple aliases at once:
alias: alias [-p] [name[=value] ... ]
Define or display aliases.
Without arguments, `alias' prints the list of aliases in the reusable
form `alias NAME=VALUE' on standard output.
Otherwise, an alias is defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked for
alias substitution when the alias is expanded.
So you can use brace expansion to generate the name=value
pairs:
alias {at,cart,cst}='/bin/cat'
So:
$ alias {at,cart,cst}='/bin/cat'
$ type at cart cst
at is aliased to `/bin/cat'
cart is aliased to `/bin/cat'
cst is aliased to `/bin/cat'
That said, look in to zsh, which has built-in typo correction (which wouldn't help for at
, but it would help for the others):
% setopt correct % sl zsh: correct `sl' to `ls' [nyae]? y % setopt correctall % ls x.v11r4 zsh: correct `x.v11r4' to `X.V11R4' [nyae]? n /usr/princton/src/x.v11r4 not found % ls /etc/paswd zsh: correct to `/etc/paswd' to `/etc/passwd' [nyae]? y /etc/passwd
If you press
y
when the shell asks you if you want to correct a word, it will be corrected. If you pressn
, it will be left alone. Pressinga
aborts the command, and pressinge
brings the line up for editing again, in case you agree the word is spelled wrong but you don't like the correction.
I don't think you can assign multiple aliases at once.
But you could loop through a list like this:
for a in cart xat vat xst cst vst dog; do alias "$a"='/bin/cat'; done
Make sure that the aliases are not already in use by other programs (like at
in your example).