[plug] Bash scripting error with functions

Bernd Felsche bernie at innovative.iinet.net.au
Sun Jun 19 17:51:45 WST 2005


Craig Ringer <craig at postnewspapers.com.au> writes:
>On Sun, 2005-06-12 at 21:38 +0930, Onno Benschop wrote:
>> Can someone explain to me why the following script returns:
>> 
>>     xargs: make_file_link: No such file or directory

>[craig at albert ~]$ function fred() {
>> echo fred
>> }
>[craig at albert ~]$ fred
>fred
>[craig at albert ~]$ bash
>[craig at albert ~]$ fred
>bash: fred: command not found

>Functions don't seem to be inherited. Chances are that xargs uses a
>subshell, or just looks for the command directly, and it won't be able
>to call `make_file_link' from the parent process (shell).

Functions aren't inherited. Functions are local to the shell process
in which they're defined.

If you want to declare common functions to be used in sub-shell,
place their definition in that shell's rc file. e.g. ~/.bashrc

Alternatively, move the "functions" into external programs somewhere
in the PATH e.g. ~/bin.
-- 
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ /  ASCII ribbon campaign | I'm a .signature virus!
 X   against HTML mail     | Copy me into your ~/.signature
/ \  and postings          | to help me spread!




More information about the plug mailing list