The current Bash defines backup.
Make the function available in subsequently started child Bash processes.
Which Bash-specific command is appropriate?
export -f NAME marks a Bash function for inheritance by child Bash processes.
Detailed explanation
export backupIncorrect. export backup treats backup as a variable name.
Incorrect. export backup treats backup as a variable name.
export -f backupCorrect. export -f backup exports the function definition to child Bash.
Correct. export -f backup exports the function definition to child Bash.
alias backupIncorrect. alias only displays or defines an alias.
Incorrect. alias only displays or defines an alias.
set -f backupIncorrect. set -f disables pathname expansion; it does not export a function.
Incorrect. set -f disables pathname expansion; it does not export a function.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'backup(){ printf "function-ok\n"; }; export -f backup; bash --noprofile --norc -c backup'Expected result
function-okKey points
- -f means function
- Child Bash inheritance
- Bash-specific
Notes
- Environment: GNU Bash 5.2 / 一時子Bash
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.