How do variables, $?, $@ and $* behave?
Assesses fundamental understanding of Shell & Bash conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Shell variables hold strings and have no strict typing. $? is the exit status of the last command, where 0 means success.
greeting="hello"
echo "${greeting} world"
readonly PI=3.14
export PATH="$PATH:/opt/bin"
${var:-default} supplies a default without assigning, ${var:=default} assigns it, ${#var} is the length and local scopes a variable to a function.
For positional parameters, the quoting rules are crucial:
"$@"expands to separate, individually quoted arguments, which is correct for forwarding."$*"joins all arguments into a single string using the first character ofIFS.$#is the argument count,$0the script name,$1and onward the arguments, andshiftdrops the first.
for arg in "$@"; do echo "$arg"; done
Always prefer "$@". Use readonly for constants, and arrays where "${arr[@]}" is the analogue of "$@".
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.