Linux Foundations_2 Flashcards
After using a text editor to create a shell script, what step should you take before trying to
use the script by typing its name?
A. Set one or more executable bits using chmod.
B. Copy the script to the /usr/bin/scripts directory.
C. Compile the script by typing bash
scriptname, where
scriptname is the
script’s name.
D. Run a virus checker on the script to be sure it contains no viruses.
E. Run a spell checker on the script to ensure it contains no bugs.
Set one or more executable bits using chmod.
Ex: chmod +x scriptname
Describe the effect of the following short script, cp1, if it’s called as cp1 big.c big.cc:
#!/bin/bash
cp $2 $1
A. It has the same effect as the cp command—copying the contents of big.c to big.cc.
B. It compiles the C program big.c and calls the result big.cc.
C. It copies the contents of big.cc to big.c, eliminating the old big.c.
D. It converts the C program big.c into a C++ program called big.cc.
E. The script’s first line is invalid, so it won’t work.
C. It copies the contents of big.cc to big.c, eliminating the old big.c.
Here’s the explanation:
The script cp1 uses the cp command to copy the file $2 (the second argument, big.cc) to $1 (the first argument, big.c).
As a result,the contents of big.cc are copied into big.c, overwriting the old big.c file.
What is the purpose of conditional expressions in shell scripts?
A. They prevent scripts from executing if license conditions aren’t met.
B. They display information about the script’s computer environment.
C. They enable the script to take different actions in response to variable data.
D. They enable scripts to learn in a manner reminiscent of Pavlovian conditioning.
E. They cause scripts to run only at specified times of day.
They enable the script to take different actions in response to variable data.
True or false: A user types myscript laser.txt to run a script called myscript. Within
myscript, the $0 variable holds the value laser.txt.
false.
When a user runs a script by typing myscript laser.txt, the $0 variable within the script holds the value of the script’s name, which in this case is myscript. The $1 variable would hold the value laser.txt.
True or false: Valid looping statements in Bash include for, while, and until.
True.
In Bash scripting, valid looping statements include for, while, and until. These loops are used to execute a block of code repeatedly based on certain conditions.
True or false: The following script launches three simultaneous instances of the terminal
program.
#!/bin/bash
terminal
terminal
terminal
False
You’ve written a simple shell script that does nothing but launch programs. To ensure that
the script works with most user shells, the first line should be .
A. #!/bin/sh
B. /bin/sh
C. # /bin/sh
D. bash
E. #!bash
A. #!/bin/sh
The Bash scripting command is used to display prompts for a user in a shell script.
A. case
B. while
C. if
D. echo
E. exit
echo
The Bash scripting command is used to control the program flow based on a variable
that can take many values (such as all the letters of the alphabet).
A. case
B. while
C. if
D. echo
E. exit
case
The Bash scripting command controls the return value generated by a script, inde-
pendent of the other commands used in the script.
A. case
B. while
C. if
D. echo
E. exit
exit
ex:#!/bin/bash
Some commands here
Exit the script with a status of 0 (success)
exit 0
Which one of the following choices is known as the shebang combination? ?
(#/!/bin/sh)
(#!/bin/sh)
(#/bin/sh/!)
(#/bin!/sh)
(#!/bin/sh)
With which command can we check to see if a command is built -in or a file?
type
file
touch
echo
type - Good job! ✅
The command type will show if a command is an alias, function, built-in keyword or file.
Which of the following quotes will allow the expansion of variables?
Double Quotes “”
Sngle Quotes ‘’
The backslash \
Double Quotes “” - Good job! ✅
Yes, these allow for variable expansion
What is each document in an info page known as?
doc
page
link
node
node✅
Which of the following commands provides the most information about your mother-
board’s features?
A. lscpu
B. Xorg -configure
C. fdisk -l /dev/sda
D. lspci
E. http://localhost:631
lspci
Why might you want to partition a hard disk? (Choose all that apply.)
A. To install more than one OS on the disk
B. To use ext4fs rather than ReiserFS
C. To turn a PATA disk into an SATA disk
D. To separate filesystem data from swap space
E. To separate the disk’s cache from its main data
A. To install more than one OS on the disk: Partitioning allows you to set aside different sections of the disk for different operating systems.
D. To separate filesystem data from swap space: Creating separate partitions for your filesystem and swap space can improve system performance and organization.