When I execute the following script
#!/usr/bin/env bash
main() {
shopt -s expand_aliases
alias Hi='echo "Hi from alias"'
Hi # Should Execute the alias
\Hi # Should Execute the function
"Hi"
}
function Hi() {
echo "Hi from function"
}
main "$@"
Very first time it executes the function and then always executes as alias:
$ . Sample.sh
Hi from function
Hi from function
Hi from function
$ . Sample.sh
Hi from alias
Hi from function
Hi from function
Why is it so?
This does not happen in the following case
#!/usr/bin/env bash
function Hi() {
echo "Hi from function"
}
shopt -s expand_aliases
alias Hi='echo "Hi from alias"'
Hi # Should Execute the alias
\Hi # Should Execute the function
"Hi"
Very first time it executes the function and then always executes as alias:
$ . Sample.sh
Hi from alias
Hi from function
Hi from function
$ . Sample.sh
Hi from alias
Hi from function
Hi from function