How to use aliases defined in .bashrc in other scripts? How to use aliases defined in .bashrc in other scripts? bash bash

How to use aliases defined in .bashrc in other scripts?


You need to do shopt -s expand_aliases in the script in addition to sourcing ~/.bashrc.


The simplest answer is to do the 2 important things or it wont' work.

#!/bin/bash -i# Expand aliases defined in the shell ~/.bashrcshopt -s expand_aliases

After this, your aliases that you have defined in ~/.bashrc they will be available in your shell script (giga.sh or any.sh) and to any function or child shell within such script.

If you don't do that, you'll get an error:

your_cool_alias: command not found


I had this problem and I reloaded the file with this command to fix it.

$ source ~/.bashrc