This quiz is part of the DevOpsTheHardWay course.

Please answer the quiz and click the "Test" button at the bottom right.

Bash - Linux shells - multichoice questions

Question 1

Which of the following would the bash shell interpret as a comment?

Question 2

Upon a new terminal session, commands from what file are automatically executed by bash?

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?

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

Question 5

Immediately after the pstree command, the user executed the exit command. Which of the following statements most describe what happened after?

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?

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?

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?

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?

Question 10

Which of the following command lines could be used to source the file config.script?

Question 11

Which of the following commands would apply changes made to the file ~/.bashrc to the current shell?

Question 12

Which of the following files are sourced when a login shell is exited?

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?

Question 14

What permissions are needed on a file in order for it to be sourced?

Question 15

When sourcing a file with the source built-in command, what type of subshell is invoked?

license