101-500 Exam QuestionsBrowse all questions from this exam

101-500 Exam - Question 40


From a Bash shell, which of the following commands directly execute the instructions from the file /usr/local/bin/runme.sh without starting a subshell?

(Choose two.)

Show Answer
Correct Answer: AD

In Bash, the commands 'source' and '.' are used to execute a script in the current shell. 'source /usr/local/bin/runme.sh' reads and executes the instructions from the script in the current shell, meaning any changes to the environment by the script persist after the script finishes. Similarly, '. /usr/local/bin/runme.sh' does the same thing; the dot (.) is an alternative to the 'source' command in Bash. Both do not start a new subshell, ensuring the script runs within the current shell environment.

Discussion

13 comments
Sign in to comment
NegatorOptions: AD
Mar 23, 2021

Create a script that outputs the shell level environmental variable using "echo $SHLVL". When you execute this script using source or dot (.) it will display 1 showing that the script was executed in the current shell. When you execute the script using full path it will show 2, showing that the script was executed in a subshell.

CuriousLinuxCatOptions: AD
Jul 24, 2021

A and D is correct. source and . tested on Ubuntu.

VendoOptions: AD
Aug 17, 2020

When a script is run using source it runs within the existing shell, any variables created or modified by the script will remain available after the script completes. source is a synonym for dot/period '.' in bash. Be careful! ./ and source are not quite the same. ./script runs the script as an executable file, launching a new shell to run it https://ss64.com/bash/source.html

ilputtoOptions: AD
Oct 25, 2020

the correct one is A and D. source <script> and . ./<script> are equivalent

jsteven845Options: AD
Mar 12, 2021

A and D

deewetdvjbmnjkjytfdszxcOptions: AD
Jul 25, 2020

Isn't A+B?

mrironOptions: AD
Dec 19, 2020

A and D are correct, assuming there is a space after (.) point for D . B is wrong , because it execute in the kind shell not in current shell

Vano1
Aug 3, 2020

The correct answer is A, B. Verified on CentOS7.

Vano1
Aug 4, 2020

D is correct if between . (dot) and /usr/loca/bin/runme.sh is a space. This question have 3 correct answer or I don't understand something.

Vano1
Aug 4, 2020

After some researchers, I choose A and D.

snota45
Aug 4, 2020

it is A & C

MIUOptions: AD
Nov 23, 2020

A and D are correct. When you try, just copy and paste from the question. You guys sometimes typo when you try then on your environment....

MchoetiOptions: AD
Mar 22, 2023

right A and D

NinymoOptions: AD
Mar 24, 2024

Answer: AD

Aleksandre
Jul 18, 2024

Maybe something changed here. Correct answer is A and B tried on arch linux. running bash script using absolute path does not creates subshell (does not increments $SHLVL variable)