I noticed an example from https://unix.stackexchange.com/a/383825/674
$ alias foo=bar $ foo () { blah "$@"; } $ type -a foo bar foo is aliased to `bar' bar is a function bar () { blah "$@" } So redefining the alias foo actually redefines the aliased command bar. This works like a nameref, i.e. a variable with the reference attribute.
I experimented more with the following examples.
Why does
mya=catnot re-aliasmyatocat, nor redefines the aliasedechotocat?Why does
mya () { cat test.sh; }redefine the aliasedechoto the function, just like a nameref?
Thanks.
$ alias mya=echo $ type mya mya is aliased to `echo' $ mya abc # mya behaves exactly as echo abc $ mya=cat $ type mya mya is aliased to `echo' $ mya test.sh # mya=cat doesn't alias mya to cat test.sh $ mya () { cat test.sh; } $ type mya mya is aliased to `echo' $ mya # Redefining mya as a function works, by outputing the content of test.sh #! /usr/bin/env bash echo $_ echo $0 $ echo # Redefining mya also redefines the aliased echo, just like a nameref #! /usr/bin/env bash echo $_ echo $0
mya=catdefines a variable, not an alias. You'd have to use$myato access the variable's value.alias foo=bar; function foo () { echo booh }→ The aliasfooshadows the functionfoo(like it would for normal programs, see the ubiquitousalias rm='rm -i'), but as usual you can circumvent the alias by calling\foo.