Caglayan Dokme
Caglayan Dokme

Reputation: 1197

How to properly export all functions in a shell script?

In Bash, I've got a script-helpers.sh file to be sourced by other scripts to access common utilities like log functions, color codes, etc. I want to export all the functions in this script. What is the proper way?

If I use the syntax below, it works. But, shellcheck warns.

# ... some functions 

for func in $(declare -F | awk '{print $3}'); do
    export -f ${func}
done

shellcheck warning, SC2163.

This does not export 'func'. Remove $/${} for that, or use ${var?} to quiet.

Upvotes: 0

Views: 36

Answers (0)

Related Questions