LX0-103 · Question #205
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. The 'source' command and its dot (.) alias both execute a script in the current shell environment without spawning a subshell, so variables and functions defined in the script persist in the calling shell.
Question
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.)
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
(25 responses)- A92% (23)
- C4% (1)
- E4% (1)
Why each option
The 'source' command and its dot (.) alias both execute a script in the current shell environment without spawning a subshell, so variables and functions defined in the script persist in the calling shell.
The 'source' built-in reads and executes commands from the specified file within the current shell process, so no subshell is forked and any environment changes such as variable assignments affect the calling shell directly.
The dot (.) command is the POSIX-standard equivalent of 'source' and behaves identically - it executes the script in the context of the current shell without forking a child process.
'/bin/bash /usr/local/bin/runme.sh' explicitly launches a new bash interpreter as a subshell, which is the opposite of what is required.
Executing the script directly by its path causes the shell to fork a child process to run it, so environment changes in the script do not affect the parent shell.
'run' is not a standard bash built-in or common Unix command and would result in a 'command not found' error.
Concept tested: Source command vs subshell script execution
Source: https://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Builtins
Topics
Community Discussion
No community discussion yet for this question.