010-160 · Question #95
Which of the following statements are true regarding a typical shell script? (Choose two.)
The correct answer is A. It has the executable permission bit set. A shell script must have the executable permission bit set so the operating system will permit it to run directly as a program.
Question
Options
- AIt has the executable permission bit set.
- BIt starts with the two character sequence #!.
- CIt is located in /usr/local/scripts/.
- DIt is located in /etc/bash/scripts/.
- EIt is compiled into a binary file compatible with the current machine architecture.
How the community answered
(47 responses)- A91% (43)
- B2% (1)
- C4% (2)
- E2% (1)
Why each option
A shell script must have the executable permission bit set so the operating system will permit it to run directly as a program.
For a shell script to be executed directly (e.g., './script.sh'), the filesystem executable permission bit must be set via chmod. Without it, the kernel returns a permission denied error and refuses to run the file.
While the shebang (#!) is a widely used convention specifying the interpreter, it is not strictly required - a script can be run by passing it directly to the interpreter (e.g., bash script.sh) without one.
Shell scripts can reside in any directory accessible to the user; no Linux standard mandates placement in /usr/local/scripts/.
There is no standard /etc/bash/scripts/ directory defined by the Linux Filesystem Hierarchy Standard for shell scripts.
Shell scripts are interpreted text files executed by a shell at runtime and are never compiled into machine-code binaries.
Concept tested: Shell script execution requirements and file permissions
Source: https://www.gnu.org/software/bash/manual/bash.html#Executing-Commands
Topics
Community Discussion
No community discussion yet for this question.