In ~/.bashrc, I defined some aliases. But I cannot use them in other shell scripts, where I can only use aliases defined right there. Even though I sourced bashrc, it still did not work. What should I do?
PS. I'm in bash.
Bash Alias allows to aggregate multiple functions into a single command and also it avoids repetitive or large commands into a simple shortcut command. BASH Alias is a map of shortcut command with the sets of commands which are stored in a file called either . bash_profile or . bashrc with a specific syntax.
bashrc or in ~/. bash_aliases but it should not go in . profile . If the variables are only ever needed in shells where the aliases (which expand to commands that use them) are available, then it is actually fine to put them in the same place as the aliases.
bash_aliases is present under the user home directory and load it whenever you initiate a new terminal session. You can also create a custom alias file under any directory and add definition in either . bashrc or . profile to load it.
You need to do shopt -s expand_aliases
in the script in addition to sourcing ~/.bashrc
.
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