nerdexam
IBM

000-221 · Question #189

The first line of a script is: #.' /us r/bin /perl What will this do when the script is run?

The correct answer is A. It will interpret the script using Perl. The first line of a script beginning with #! (shebang) specifies the interpreter the kernel should use to execute the script. In this case, /usr/bin/perl is designated as the interpreter.

System Management

Question

The first line of a script is:

#.' /us r/bin /perl What will this do when the script is run?

Options

  • AIt will interpret the script using Perl.
  • BIt will load environment variables in the /usr/bin/perl file.
  • CIt will execute the file /usr/bin/perl before executing the script.
  • DIt will set the value of the "perl" environment variable to the empty string

How the community answered

(53 responses)
  • A
    81% (43)
  • B
    9% (5)
  • C
    8% (4)
  • D
    2% (1)

Why each option

The first line of a script beginning with #! (shebang) specifies the interpreter the kernel should use to execute the script. In this case, /usr/bin/perl is designated as the interpreter.

AIt will interpret the script using Perl.Correct

The #! sequence (shebang) on the first line is a Unix/Linux kernel directive that names the program used to interpret the rest of the file. When this script is executed, the kernel invokes /usr/bin/perl and passes the script file as its argument. All subsequent lines are therefore parsed and run as Perl code.

BIt will load environment variables in the /usr/bin/perl file.

The shebang line does not load or source environment variables; sourcing is done with the dot (.) or source command in shell scripts.

CIt will execute the file /usr/bin/perl before executing the script.

The shebang does not run /usr/bin/perl as a standalone script before the current script; it uses perl as the interpreter for the current script itself.

DIt will set the value of the "perl" environment variable to the empty string

The shebang has no relationship to environment variable assignment; it is purely a kernel mechanism for interpreter selection.

Concept tested: Unix shebang line and interpreter selection

Source: https://www.man7.org/linux/man-pages/man2/execve.2.html

Topics

#shebang#shell scripting#Perl#script interpreter

Community Discussion

No community discussion yet for this question.

Full 000-221 Practice