In a non-interactive bash script, these work:
alias hi="echo hi"
shopt -s expand_aliases
hi
alias hi="echo hi"
if [[ 1 ]]; then
shopt -s expand_aliases
fi
hi
shopt -s expand_aliases
if [[ 1 ]]; then
alias hi="echo hi"
fi
hi
alias hi="echo hi"
shopt -s expand_aliases
if [[ 1 ]]; then
hi
fi
But these do not
alias hi="echo hi"
if [[ 1 ]]; then
shopt -s expand_aliases
hi #hi: command not found
fi
shopt -s expand_aliases
if [[ 1 ]]; then
alias hi="echo hi"
hi #hi: command not found
fi
Can anyone explain why?
Could it be related to this?
Aliases are expanded when a command is read, not when it is executed.
Does this mean entire bash conditionals read before execution?