Question: I generally add multiple aliased and bash functions in my .bashrc file. eg g for "grep -nri ..." , v for vim etc. However some time my new OS has some of the cmds which is get overwritten by my alias hence I see unexpected build failures.

Is there any way to add alias/function in bashrc which should run only on interactive shell and should not run via makefile or other scripts?

Thanks...

Answer: 
Expansion of bash aliases is by default disabled in non-interactive sessions (e.g. when executing a script).

Do you somewhere execute `shopt -s expand_aliases` in you're .bashrc/.profile? This enables alias expansion in non-interactive sessions.

To be 100% safe, you could execute `shopt -u expand_aliases` before running e.g. the make script. This will unset the `expand_aliases` flag.

Another approach is to stop sourcing the bash config files altogether when running a non-interactive session. This is achieved by adding this line to you're .profile or .bashrc:

```
[[ $- =~ i ]] && return

```

Code before that line is still executed in non-interactive sessions. Make sure to add the custom aliases and functions below.
Aliases and shortcut functions should not be defined for non-interactive shells, as other shell scripts can be confused about your customizations (as you've found out). It's also good for performance if shells that execute scripts do not need to read and process all of your customizations.

Usually, you do this via a guard clause at the end of your `~/.bashrc`. Put your customizations after that guard.

```
# Generic settings (exports, PATH, ...) here.
# ...

case "$-" in
    *i*) ;;
    *)   return;;
esac

# Aliases and shortcut functions here
alias rm=...
grep()
{
    ...
}

```