A systems administrator working in Bash has just defined a function named backup_db() that compresses the database directory. The function works in the current shell, but the admin also wants to call it from a subshell that will be started later in the same session (for example, by typing bash). Which one of the following commands will make the backup_db() function available inside that subshell without having to redefine it there?
The export builtin can mark not only variables but also shell functions for inheritance by child processes. When the -f option is supplied, Bash treats the name that follows as a function and places its definition in the environment of subsequent commands. Therefore, running export -f backup_db exports the existing backup_db() function so that any subshell started afterwards can invoke it immediately. Using export without -f would attempt to export a variable named backup_db, not the function. declare -f backup_db merely prints the function definition, and the alias command creates a shell alias that is not propagated to child shells.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does 'export -f' do in Bash?
Open an interactive chat with Bash
How is 'export -f' different from just 'export'?
Open an interactive chat with Bash
Why doesn’t an alias work in subshells?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access