Are there any single character bash aliases to be avoided?
Things to avoid:
- standard or common commands with single character names:
w
(show logged in users' activity),X
(X Window System server),R
(R programming language interpreter),[
(similar totest
) - builtins of your shell or of common shells:
[
,.
,:
,-
,r
- shell keywords:
{
,}
,!
?
and*
wildcard characters- special characters in the shell syntax:
`"$&();'#~|\<>
, (also^
,%
in some shells), SPC, TAB, NL (and other blanks with some shells) - better avoid non-ASCII characters (as those have different encoding depending on the locale)
- better avoid control characters (beside TAB and NL already mentioned above) as they're not that easy to enter, and depending on context, not always visible, or with different representations. Only
zsh
will let you define and use an alias for the NUL character.bash
lets you define an alias for^A
(the control character with byte value 1) but not use it apparently.
To find commands with single character names:
bash
:compgen -c | grep -x . | sort -u
(also includes keywords, assumes command names don't contain newline characters)zsh
:type -m '?'
(ortype -pm '?'
if you don't want functions/aliases/builtins/keywords).Debian or derivatives: to find any command in any package with single character name:
$ apt-file find -x '/s?bin/.$' coreutils: /usr/bin/[ e-wrapper: /usr/bin/e python3-q-text-as-data: /usr/bin/q r-base-core: /usr/bin/R r-base-core: /usr/lib/R/bin/R r-cran-littler: /usr/bin/r r-cran-littler: /usr/lib/R/site-library/littler/bin/r wims: /var/lib/wims/public_html/bin/c xserver-xorg-core: /usr/bin/X
The simplest way is probably to check whether something with that name already exists. On my system:
$ for char in {A..z}; do type "$char" 2>/dev/null; done
R is /usr/bin/R
X is /usr/bin/X
[ is a shell builtin
l is aliased to `ls -CF'
w is /usr/bin/w
As far as I know this shows all relevant collisions:
- Other aliases like
l
- Shell reserved words
- Functions
- Shell builtins
- File commands such as
w
and[
Addressing: "I'm curious if this should be avoided."
As described in the other answers, there should be no technical problem as long as the command you are overriding with the alias it isn't something you are going to use.
The main frustration with using aliases like this is when you are helping a friend or ssh into a computer where you haven't copied your .bashrc yet. All of the muscle memory you've developed makes you feel like a fish out of water. I find it so disorienting that I try to keep my aliases to a minimum.