Refer to the exhibit. What is the action of the Bash script that is shown?
A.
For all directories in the current folder, the script goes into the directory and makes a new directory.
B.
The script waits until input is entered. If the directory exists, the script goes into it until there is no directory with the same name, then it creates a new directory.
C.
The script waits until input is entered, then it goes into the directory entered and creates a new directory with the same name.
D.
The script goes into the directory called ג€$ndirג€ and makes a new directory called ג€$ndirג€.
tested script in shell. It is B.
read = Ask user for input saved as $ndir (DIR NAME)
check if this exists - if yes, cd into it.
if not exist - create $ndir.
I tested. The answer is B. The script waits until input is entered. So A & D are wrong. The script creates the folder if id doesn’t exist. So C is wrong “goes into the directory entered”.
I also tested the script and it does that.
read command waits for input and then assigns the input to the variable ndir.
the while command checks if a directory with that name exists, if it does, it will cd into that directory and then loop and check again if there is a directory with that name.
When it no longer finds a directory with that name, it will create one:
Here is the script run three times. Each time it is run, it waits and I type the word "folder" and hit enter key.
$ cat ../ndir.sh
#!/bin/bash
read ndir
while [ -d $ndir ]
do
cd $ndir
done
mkdir $ndir
$
$ tree
.
0 directories, 0 files
$ ../ndir.sh
folder
$ tree
.
└── folder
1 directory, 0 files
$ ../ndir.sh
folder
$ tree
.
└── folder
└── folder
2 directories, 0 files
$ ../ndir.sh
folder
$ tree
.
└── folder
└── folder
└── folder
3 directories, 0 files
$
This section is not available anymore. Please use the main Exam Page.200-901 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
jonasff
Highly Voted 4 years, 7 months agoFireTv
Highly Voted 4 years, 7 months agokymoni
Most Recent 10 months agomacxsz
2 years, 7 months agoDenskyDen
3 years, 10 months agouzbin
4 years, 1 month agobpbenabd
4 years, 3 months agogarcesdavid88
4 years, 4 months agoTechBrain
4 years, 6 months agopsyborg
4 years, 5 months agoafsarmahmood
4 years, 6 months agoReadTheDoc
4 years, 7 months agogeex
3 years, 11 months agoJM_Lee
4 years, 7 months agoJM_Lee
4 years, 7 months ago