Interview Prep/Shell Scripting/Best practices and rapid-fire commands

Rapid fire: what does each of these print or do?

IntermediateConceptBest practices and rapid-fire commands
Answer
echo "${#PATH}"                  # length of PATH in characters
echo "${0##*/}"                  # script name without directory
echo "$(( 7 / 2 ))"              # 3 (integer division)
set -- a "b c"; echo $#          # 2
x=; echo "${x:-empty}"           # empty
true | false; echo $?            # 1 (last command)
false | true; echo $?            # 0 (1 with pipefail)
[[ 10 < 9 ]] && echo yes         # yes (string comparison)
printf '%q\n' "it's a test"      # it\'s\ a\ test
type cd                          # cd is a shell builtin

Interviewers use questions like these to check you understand expansion and exit-status rules, not just syntax.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Best practices and rapid-fire commands