CORRECT DETAILED ANSWERS LATEST UPDATE 2025
ALREADY GRADED A+ PROFESSOR VERIFIED.
✅What does the following do?
((i<1?++i:--i)). Answer: It says that if i is less than 1, to add 1 to i, else subtract 1 from i. It
effectively works like a toggle switch
✅Can you use regex as your identifier in a case statement?. Answer: Nope. case statements
use globs (which I believe are like parameter expansions), not regex.
✅What do these assignment operators do?
a=5
a += 5
a -= 5
a *= 5
a /= 5
a %= 5
a++
a--
++a
--a. Answer: sets a equal to 5
sets a equal to a + 5
sets a equal to a - 5
sets a equal to a * 5
,sets a equal to a integer divided by 5
sets a equal to a modulus divided by 5
sets a equal to a + 1. If you echo with echo $((a++)) then it will echo a before the addition,
and THEN add the 1 to a
sets a equal to a - 1. If you echo with echo $((a--)) then it will echo a before the subtraction
sets a equal to a + 1. If you echo with echo $((++a)) then it will echo a after the addition
sets a equal to a - 1. If you echo with ecoh $((--a)) then it will echo a after the subtraction
✅Where does the & symbol go when redirecting output?. Answer: It always goes before the
#
✅Create an array with "a dog", "a cat", and "a fish" as elements. Then print out just the
second element ("a cat"). Then print out each element separately using one catchall
command. Then add on "a cow" and "a duck" to the end of the array. Now show them all
again like you did before. Now list the number of elements and what each element is..
Answer: [ mjollnerd@gazelle: ~ ] $> animals=("a dog" "a cat" "a fish")
[ mjollnerd@gazelle: ~ ] $> echo ${animals[1]}
a cat
[ mjollnerd@gazelle: ~ ] $> for i in "${animals[@]}"; do echo $i; done
a dog
a cat
a fish
[ mjollnerd@gazelle: ~ ] $> animals+=("a cow" "a duck")
[ mjollnerd@gazelle: ~ ] $> for i in "${animals[@]}"; do echo $i; done
a dog
a cat
a fish
a cow
a duck
[ mjollnerd@gazelle: ~ ] $> echo ${#animals[@]}
5
, ✅If you're looking for a man page for something, but nothing is showing up (such as read),
what do you do?. Answer: help command
So in this example:
help read
✅What does the "shift" command do?. Answer: It assigns the value of $2 to $1 and then
unsets $2.
✅What does the following do?
while read i; echo $i; done < file.txt. Answer: It creates a variable "i" for each line in "file.txt"
and then echoes them one at a time.
✅What does do the following do?
$@
$$
$!. Answer: prints out all command arguments. Useful for creating a for loop.
prints out the PID of the currently running shell script.
prints out the PID of the last background process entered.
✅How would you create defaults into your read?
For example, if you wanted to prompt a user with "What is your name? [bob] " How would
you do it so that if they press enter, bob is stored as the answer?. Answer: echo "What is your
name? [$(whoami)] "
read myname