nerdexam
CompTIA

LX0-104 · 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 include a shebang line pointing to its interpreter. These three elements ensure the system can find, execute, and correctly interpret t

Shells, Scripting and Data Management

Question

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.)

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

(30 responses)
  • A
    7% (2)
  • B
    83% (25)
  • E
    10% (3)

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 include a shebang line pointing to its interpreter. These three elements ensure the system can find, execute, and correctly interpret the script.

AThe user issuing the command must be in the group script.

Being in a specific group like "script" is not a general requirement for executing a shell script; file permissions (user, group, other) determine access.

BThe script file must be found in the $PATH.Correct

For a script to be run like a command from any directory without specifying its full path, its directory must be included in the `PATH` environment variable. The shell searches directories listed in `$PATH` to find executables.

CThe script file must have the executable permission bit set.Correct

The executable permission bit (e.g., `chmod +x script.sh`) must be set on the script file. Without this permission, the operating system will not allow the file to be directly executed.

DThe script must begin with a shebang-line (#!) that points to the correct interpreter.Correct

A shebang line, starting with `#!` followed by the path to the interpreter (e.g., `#!/bin/bash`), is crucial. It tells the operating system which program should be used to execute the script when it's run as a standalone executable.

EThe file system on which the script resides must be mounted with the option scripts.

There is no standard filesystem mount option called "scripts" that enables script execution. Executability is controlled by file permissions and the `noexec` mount option, if present, but not a positive "scripts" option.

Concept tested: Linux shell script execution - requirements

Source: https://www.gnu.org/software/bash/manual/bash.html#Invoking-Shell-Scripts

Topics

#shell scripting#executable permissions#PATH environment variable#shebang

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice