Aliases sourced from file are not available when run in subshell [duplicate]

Solution 1:

You can't (in the usual ways). See the Bash manual's section on Aliases (emphasis mine):

The rules concerning the definition and use of aliases are somewhat confusing. Bash always reads at least one complete line of input, and all lines that make up a compound command, before executing any of the commands on that line or the compound command. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read. The commands following the alias definition on that line are not affected by the new alias. [...] To be safe, always put alias definitions on a separate line, and do not use alias in compound commands.

You can work around it by forcing a re-parsing using eval:

$ alias x=date; eval x
Fri Nov 12 18:20:54 JST 2021