Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make aliases work across all the shells?

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?

like image 256
Pensu Avatar asked Nov 20 '25 01:11

Pensu


1 Answers

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.

like image 65
William Pursell Avatar answered Nov 21 '25 21:11

William Pursell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!