LFCS · Question #805
From a Bash shell, which of the following commands directly executes the instruction from the file /usr/ local/bin/runme.sh without starting a subshell? (Please select TWO answers.)
The correct answer is A. source /usr/local/bin/runme.sh B. . /usr/local/bin/runme.sh. This question assesses knowledge of how to execute a script within the current shell environment without creating a new subshell process.
Question
Options
- Asource /usr/local/bin/runme.sh
- B. /usr/local/bin/runme.sh
- C/bin/bash /usr/local/bin/runme.sh
- D/usr/local/bin/runme.sh
- Erun /usr/local/bin/runme.sh
How the community answered
(47 responses)- A87% (41)
- C4% (2)
- D6% (3)
- E2% (1)
Why each option
This question assesses knowledge of how to execute a script within the current shell environment without creating a new subshell process.
The `source` command is a shell built-in that reads and executes commands from the specified file in the current shell environment, meaning no new subshell is created and variables/functions are inherited by the parent shell.
The `.` (dot) command is an alias for `source` in Bash, performing the exact same function of executing a script within the current shell context without spawning a subshell.
`/bin/bash /usr/local/bin/runme.sh` explicitly starts a *new* Bash subshell to execute the script.
`/usr/local/bin/runme.sh` executes the script by creating a *new* process, typically a subshell, to run it.
`run` is not a standard shell command for executing scripts without creating a subshell.
Concept tested: Executing scripts in current shell environment
Source: https://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Builtins
Topics
Community Discussion
No community discussion yet for this question.