bashfunctionredeclare

how to find file and run as source script?


I have folder with number of different files that contains functions. I use declare to publish those functions to users. This is sample function I use:

space () { 
 df -h
} 
declare -f space

Under user .bashrc I have added following:

for FILE in $HOME/functions/* ; do source $FILE ; done

However I get this message:

-bash: source: /home/user/functions/subdirectory: is a directory

Can anyone advise how to fix that or maybe there is better way to load functions to shell variables not to environment variables?


Solution

  • Thanks for all answers and here is the update what works for me.

    MYFUNC=$(find ~/functions -type f)
    for f in $MYFUNC ; do
    source $f > /dev/null 2>&1
    done
    

    Thanks for help