I have written some scripts and stored them in my ~/bin
folder. I'm already able to run them just by calling their title during a shell session. However, they aren't running interactively (I mean, my ~/.bashrc
aliases are not loaded).
Is there a way to mark them to run interactively by default? Or must I source ~/.bashrc
inside of them to use any aliases defined there?
Other alternatives are welcome!
~/.bashrc
by default? Because interactive shells come with some surprises, like ignoringSIGTERM
bashrc
's aliases in the scripts even when call them through bin referencealias hw='echo hello world'
vshw() { echo hello world; }
-i
flag,bashrc
functions are not loaded just like its aliasesshopt -s expand_aliases; . ~/.bashrc
at the beginning of your script (~as in the non-accepted answer). You still have to modify a script to change its shebang, and as I already said, theinteractive
mode comes with some changes in behaviour which are not desirable in a shell script. And, as @kojiro said, better use functions instead of aliases. Aliases only have advantages when used in an real interactive shell, I cannot think of any reason to use them in a script.