Shell & Bash Interview Questions and Answers

Scripting, pipes, permissions, process management and automation.

Practise 10 random 2 peer-reviewed questions
Shell & Bash Interview Syllabus & Preparation Strategy

Whether you are preparing for entry-level Shell & Bash interview questions for freshers or senior software engineer interview questions addressing concurrency, scalability, and system architecture, this track provides peer-reviewed model answers with syntax walkthroughs, edge cases, and practical interview tips.

1 What is the difference between single quotes and double quotes? Easy

Single quotes preserve everything literally, while double quotes allow variable expansion, command substitution and some escape sequences.

name="world"
echo 'hello $name'    # hello $name
echo "hello $name"    # hello world
echo "total: $(wc -l < file)"

The most important habit is to double-quote variable expansions such as "$var", "$@" and "$(cmd)" to prevent word splitting and glob expansion. An unquoted expansion containing spaces becomes several arguments:

files="a b c"
for f in $files; do echo "$f"; done    # three iterations
for f in "$files"; do echo "$f"; done  # one iteration

Inside double quotes, $, backticks, backslash and, interactively, ! are special. Single-quoted strings have no escapes at all, so including a single quote requires ending the string, escaping and reopening it: 'it'\''s'. The $'...' form enables escape sequences.

2 How do file permissions and chmod work? Easy

Every file has permissions for owner, group and others, each with read (4), write (2) and execute (1). chmod changes them in symbolic or octal form.

chmod 644 notes.txt     # rw- r-- r--
chmod 755 script.sh     # rwx r-x r-x
chmod u+x script.sh     # add execute for the owner
chmod g-w file          # remove write for the group

Directories need execute permission to enter or traverse them, and read permission to list names. Special bits include setuid, setgid and the sticky bit, as in 1777 on /tmp, which lets only the owner delete their own files.

chown user:group file changes ownership, and umask controls default permissions for new files. A common umask of 022 yields 644 files and 755 directories.

A script must be readable by the interpreter and executable, or you invoke it as bash script.sh. Follow least privilege and avoid 777.

Frequently Asked Questions About Shell & Bash Interviews

What do hiring managers evaluate in Shell & Bash technical rounds?

Technical interviewers look for foundational fluency, idiomatic syntax, clarity when communicating complex logic, and awareness of performance trade-offs (e.g. memory footprint, render performance, and network latency) in production environments.

What are the best interview tips for practicing Shell & Bash questions?

Use active recall: summarize each answer in your own words before revealing the model solution. Focus on explaining why a certain approach is chosen rather than just memorizing code syntax.