I have been trying to make aliases work in bash shell. Now, let's say I do alias yum='yum -v' in my shell. It works when I run the run the command from CLI. But when I run a script it doesn't have any effect. How can I make the aliases work across the shell?
In bash, you can export functions, so if you do:
yum() { command yum -v "$@"; }
export -f yum
Then the 'alias' for yum will persist in subshells. Note that functions are almost always preferred to aliases, and (from the bash man page) "For almost every purpose, aliases are superseded by shell functions.". I believe the initial clause 'For almost every purpose' is merely hyberbole and that 'almost' can be safely omitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With