A system administrator writes a shell script that first defines a variable named API_KEY and then executes a separate compiled program. The program is designed to read the API_KEY value from its execution environment. When the script is run, the program fails because it cannot find the API_KEY variable. Which of the following commands must be added to the script before the program is executed to resolve this issue?
The correct command is export API_KEY. In shell scripting, a variable created with API_KEY="value" is a shell variable, which is local to the current shell process. It is not automatically passed to child processes, such as the compiled program being executed. The export command marks a shell variable to be included in the environment of subsequently executed child processes. Therefore, exporting the API_KEY variable makes it available to the program. local API_KEY would restrict the variable's scope to a function, which is the opposite of the desired effect. set is used for setting shell options and positional parameters, not for making variables available to child processes. The env command is used to run a command in a modified environment or to list current environment variables, not to export a variable from the current shell.
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 is the difference between a shell variable and an environment variable?
Open an interactive chat with Bash
How does the `export` command work?
Open an interactive chat with Bash
What happens if you use `local` instead of `export` for a variable?
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