On 27 Sep 2007, at 11:36 am, Chris G wrote:
How do you get aliases to work in bash shell scripts?
At the moment the only way I can get an alias that I have defined in my .bashrc file to work in a script is to explicitly source .bashrc in the shell script. Is this the only way it can be done?
The korn shell can do 'alias -x fred=bert' which means that fred will work as an alias for bert in scripts called from a command line ksh where the alias is in effect. Is there no way that bash can export aliases so they work in scripts?
A quick Google search suggests that bash really can't export its aliases, which is a pity. Does anyone know otherwise?
Have you looked at the bash man page?
This seems relevant:
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below).
Thanks,
David