LFCS · Question #92
Which of the following are requirements in order to run a shell script like a regular command from anywhere in the filesystem? (Choose THREE correct answers.)
The correct answer is B. The script file must be found in the $PATH. C. The script file must have the executable permission bit set. D. The script must begin with a shebang-line (#!) that points to the correct interpreter. To execute a shell script as a regular command from any location, it must be located within the system's $PATH, have executable permissions, and specify its interpreter with a shebang line.
Question
Options
- AThe user issuing the command must be in the group script.
- BThe script file must be found in the $PATH.
- CThe script file must have the executable permission bit set.
- DThe script must begin with a shebang-line (#!) that points to the correct interpreter.
- EThe file system on which the script resides must be mounted with the option scripts.
How the community answered
(47 responses)- A4% (2)
- B94% (44)
- E2% (1)
Why each option
To execute a shell script as a regular command from any location, it must be located within the system's `$PATH`, have executable permissions, and specify its interpreter with a shebang line.
There is no standard requirement for a user to be in a specific group named "script" to execute a shell script.
For a script to be run by simply typing its name without a full path from any directory, its directory must be included in the user's `$PATH` environment variable, which the shell searches for commands.
Executable permissions (e.g., `chmod +x script.sh`) are essential for the operating system to allow a script to be run directly by the user, indicating it is an executable program.
The shebang line `#!` at the beginning of a script specifies the interpreter (e.g., `#!/bin/bash`) that should be used to execute the script, allowing the system to run it correctly without explicitly calling the interpreter.
Filesystems are not typically mounted with an "scripts" option; executable permissions and the `$PATH` variable handle script execution, not a mount option.
Concept tested: Shell script execution requirements
Source: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Invoking-Shell-Scripts
Topics
Community Discussion
No community discussion yet for this question.