Please answer the quiz and click the "Test" button at the bottom right.This quiz is part of the DevOpsTheHardWay course.
Bash - Linux shells - multichoice questions
Question 1
Which of the following would the bash shell interpret as a comment?
-
/* blagh */
-
% blagh
-
# blagh
- B and C
- None of the above
Question 2
Upon a new terminal session, commands from what file are automatically executed by bash?
-
~/bash_startup
-
~/.bash_startup
-
~/.bash
-
~/.bashrc
- None of the above
Consider the below output of the pstree command:
myuser@hostname:~$ pstree
systemd─┬─acpid
├─2*[agetty]
├─amazon-ssm-agen─┬─ssm-agent-worke───8*[{ssm-agent-worke}]
│ └─8*[{amazon-ssm-agen}]
├─apache2───5*[apache2]
├─chronyd───chronyd
├─cron
├─dbus-daemon
├─irqbalance───{irqbalance}
├─multipathd───6*[{multipathd}]
├─networkd-dispat
├─polkitd───2*[{polkitd}]
├─rsyslogd───3*[{rsyslogd}]
├─snapd───10*[{snapd}]
├─gnome-terminal───bash───bash───bash───bash───pstree
├─systemd───(sd-pam)
├─systemd-journal
├─systemd-logind
├─systemd-network
├─systemd-resolve
├─systemd-udevd
└─unattended-upgr───{unattended-upgr}
Answer the following 3 questions:
Question 3
Which of the following statements best describes the set of commands the user has executed in his opened terminal session?
- The user has executed the
bash
command 3 times, thenpstree
- The user has executed the
bash
command 4 times, thenpstree
- The user has executed the
bash
command 2 times, thenpstree
- None of the above
Question 4
According to the following line, taken from the pstree
output, how many login and non-login shells are opened? Hint: the first bash process is considered a login terminal session.
├─gnome-terminal───bash───bash───bash───bash───pstree
- 4 non-login
- 1 non-login, 3 login
- 3 non-login, 1 login
- 4 login
- None of the above
Question 5
Immediately after the pstree
command, the user executed the exit
command.
Which of the following statements most describe what happened after?
- The terminal window was closed
- The current prompt belongs to the 3rd bash session
- The computer is turning off
- The 4th bash process was terminated
- B and D correct
- None of the above
Question 6
Consider the below script named myscript.sh
:
#!/bin/sh
X=1
echo $X
The script is executed by bash myscript.sh
. Which shell is running the script?
-
bash
-
sh
- Depends on the user’s definition in
/etc/profile
- Depends on the user’s definition in
~/.bashrc
Question 7
Consider the below terminal output:
myuser@hostname:~$ echo hi > file.txt
?????: file.txt: restricted: cannot redirect output
Which is most likely the running shell?
- sh
- bash
- zsh
- rbash
- We can’t determine
Question 8
The user myuser
adds the following lines to the files ~/.bashrc
and ~/.bash_profile
.
[myuser@station]$ echo 'echo "sourcing ~/.bashrc"' >> ~/.bashrc
[myuser@station]$ echo 'echo "sourcing ~/.bash_profile"' >> ~/.bash_profile
She then starts a new bash subshell.
[myuser@station]$ bash
sourcing ~/.bashrc
[myuser@station]$
Why did myuser
not see the line sourcing ~/.bash_profile
?
- She neglected to add execute permissions to the file ~/.bash_profile.
- Because the subshell is a non-login shell, the file ~/.bash_profile does not get sourced.
- For her changes to take effect, myuser must log out and log back in again.
- None of the above reasons apply.
Question 9
When logging in from a virtual console, myuser
sees the following:
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.19.0-1022-aws x86_64)
station login: myuser
Password:
Last login: Wed Sep 3 09:54:31 on tty2
sourcing ~/.bashrc
sourcing ~/.bash_profile
[blondie@station blondie]$
Why does the file ~/.bashrc
get sourced before the file ~/.bash_profile
?
- That is the behavior of the bash executable for login shells.
- The two files are sourced in order of modification time, and the file
~/.bashrc
had the least recent modification time. - The file
~/.bashrc
is not sourced first. For login shells, the bash shell only sources the file~/.bash_profile
directly. In the default Ubuntu configuration, this file sources the file~/.bashrc
. The line sourcing~/.bashrc
comes before the line containing theecho
commandblondie
added above. - Neither of the files are sourced by bash directly. Instead, they are both sourced by the file /etc/login, in the order implied above.
- None of the above apply.
Question 10
Which of the following command lines could be used to source the file config.script
?
-
.. config.script
-
. config.script
-
< config.script
-
bash config.script
- None of the above
Question 11
Which of the following commands would apply changes made to the file ~/.bashrc to the current shell?
-
. ~/.bash_profile
- A and B
-
. /etc/profile
-
. ~/.bashrc
- All of the above
Question 12
Which of the following files are sourced when a login shell is exited?
-
~/.bash_profile
-
/etc/bash_logout
- A and C
- None of the above
-
~/.bash_logout
Question 13
After installing a new APT package, a new file is added to the /etc/profile.d directory. Which of the following commands would apply the file’s configuration to the current shell?
-
. ~/.bashrc
-
source /etc/profile
-
bash /etc/bashrc
- All of the above
- None of the above
Question 14
What permissions are needed on a file in order for it to be sourced?
- execute permissions
- read permissions
- write permissions
- A and B
- All of the above
Question 15
When sourcing a file with the source
built-in command, what type of subshell is invoked?
- A non-interactive login shell
- An interactive non-login shell
- A non-interactive non-login shell
- The question is misguided, because no subshell is invoked when sourcing a file (the commands in the file executed in the current shell).
- None of the above