nerdexam
LPI

010-160 · Question #20

Given that the file is a valid shell script, how can this script be executed? (Choose two correct answers.)

The correct answer is D. ./test.sh E. bash test.sh. A shell script with execute permissions can be run directly using its path, or explicitly by passing it as an argument to an interpreter like bash.

The Power of the Command Line

Question

Given that the file is a valid shell script, how can this script be executed? (Choose two correct answers.)

Options

  • Arun test.sh
  • B$(test.sh)
  • Ccmd ./test.sh
  • D./test.sh
  • Ebash test.sh

How the community answered

(54 responses)
  • A
    2% (1)
  • B
    2% (1)
  • C
    2% (1)
  • D
    94% (51)

Why each option

A shell script with execute permissions can be run directly using its path, or explicitly by passing it as an argument to an interpreter like bash.

Arun test.sh

'run' is not a standard Linux command; there is no built-in or common utility by that name for executing shell scripts.

B$(test.sh)

$(test.sh) is command substitution syntax that captures output, but test.sh without a path prefix would not be found unless it is in a directory listed in PATH.

Ccmd ./test.sh

'cmd' is the Windows command interpreter and is not available or meaningful in a Linux shell environment.

D./test.shCorrect

./test.sh executes the script directly by specifying its path relative to the current directory. The leading ./ is required because the current directory is not in PATH by default, and the file's rwxr-xr-x permissions confirm it is executable.

Ebash test.shCorrect

bash test.sh explicitly invokes the bash interpreter with test.sh as an argument, which works regardless of the file's execute bit because bash reads the file as input rather than requiring OS-level execution permission.

Concept tested: Shell script execution methods and file permissions

Source: https://www.gnu.org/software/bash/manual/bash.html#Executing-Commands

Topics

#shell script execution#bash#script permissions

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice