You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export -f makes the functions accessible to child processes and subshells. However, as long as our bash script doesn't call another bash script that uses the functions defined in the parent script, we don't necessarily need export -f, since the subshells invoked inherit the current environment. To quote the Bash reference manual,
Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment
Hence, export -f doesn't seem necessary. However, it gives me peace of mind to explicitly export the global functions as opposed to the local ones. The habit originated when, for other projects, I had to write Bash libraries that were meant to be sourced. There, export -f was necessary, as user scripts were expected to use the exported library functions.
as user scripts were expected to use the exported library functions.
user scripts can access non-exported functions, provided they remain in the same process. If a user script does spawn a sub-process, I think it should be its responsibility to export the required functions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I see that in this code you add
export -f
after all functions.I don't quite get why this is necessary.
Beta Was this translation helpful? Give feedback.
All reactions