A systems administrator writes a shell script named process_logs.sh which contains commands that are only compatible with the Bash shell. When other users, whose default shell is sh, try to execute the script with ./process_logs.sh, they receive syntax errors. The administrator needs to ensure the script is always executed by the Bash interpreter, regardless of the user's default shell.
Which line should be added as the very first line of the script to resolve this issue?
The correct answer is #!/bin/bash. The #! sequence at the beginning of a script is called a shebang or interpreter directive. It instructs the operating system's program loader to use the specified program (in this case, /bin/bash) to interpret and execute the script's contents. This ensures that the script is run with the correct shell, Bash, making it independent of the user's default shell environment.
SHELL=/bin/bash is incorrect because it only sets the SHELL environment variable within the script's execution context; it does not tell the system which interpreter to use to run the script itself.
// exec /bin/bash is incorrect. In shell scripting, // does not create a comment; # does. Even if it were # exec /bin/bash, it would be treated as a comment and ignored by the interpreter. The exec command itself replaces the current process, which is not the function of an interpreter directive.
# This script requires /bin/bash is incorrect because it is only a comment. While good for human readers, a comment line is ignored by the program loader and does not affect which interpreter is used.
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 purpose of the shebang (#!) in a script?
Open an interactive chat with Bash
How does the shebang differ from setting the SHELL environment variable?
Open an interactive chat with Bash
Why would using comments, like # This script requires /bin/bash, not set the interpreter?
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...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .