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.
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)- A81% (43)
- B9% (5)
- C8% (4)
- D2% (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.
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.
The shebang line does not load or source environment variables; sourcing is done with the dot (.) or source command in shell scripts.
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.
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
Community Discussion
No community discussion yet for this question.