I know writing
source ~/.bashrc
shopt -s expand_aliases
in a bash script allows to use aliases defined in .bashrc
file.
However, I have so many bash scripts, and I cannot change all those scripts.
Is there a way to let my aliases used in all my scripts, with setting env or something?
Put the code that enables aliases and sources .bashrc
to another file, assign its path to BASH_ENV
, and export BASH_ENV
.
$ cat .bashrc
alias dt=date
$ cat my_env.sh
shopt -s expand_aliases
source ~/.bashrc
$ cat my_script
#!/bin/bash
dt
$ export BASH_ENV=my_env.sh
$ ./my_script
Tue Mar 30 07:57:50 +03 2021
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