Stephane Chazelas wrote:
> To work around that, you have to do things like this in
> /etc/profile:
> ...
> And do something similar in your ~/.profile for your ~/.bashrc.

While that is normal to do to configure interactive sessions the
original question was where should shell functions be placed for use
by scripts.  I think the above answer is a good answer but to a
different question.  It reads as if this is a suggestion to place
shell functions in a bashrc file and I wanted to clarify that that is
not the case.

Non-interactive scripts should not normally be reading system or
personal bashrc customization files.  Putting a function in a bashrc
would still not make it visible to scripts.  This of the problems that
scripts would have if user's aliases for ls='ls -F --color=always' and
rm='rm -i' were seen by scripts.  Script authors need a known stable
run environment.

In summary shell functions should be defined in the script or defined
in a file sourced by the script.

Bob


Reply via email to