Shell scripting interviews test whether you can automate real admin tasks—waiting on prompts, logging, file checks, debugging flags, and small one-liners under pressure. Below are practical questions grouped by scenario; many have more than one valid approach. For operating system interview questions (processes, memory, scheduling, Linux kernel concepts), see operating system interview questions. For C and C++ interview questions and gdb/sanitizer debugging context on Linux, see C and C++ interview questions.
Interview context and how to prepare
What do shell scripting interviews test?
Practical automation under constraints:
- File tests, loops, functions, exit codes
- Text processing (awk, sed, grep patterns)
- Debugging (
bash -x, logging withlogger) - Safe scripting habits for production cron/systemd jobs
What shell topics matter in 2026?
set -euo pipefailand defensive scripting- ShellCheck in CI pipelines
- systemd timers vs cron for scheduled jobs
- Container entrypoints—scripts must handle signals and PID 1
Interviewers care that you write idempotent scripts with clear failure modes.
Interactive automation and expect
How can you create a script that will wait for specific output and hence will act according to it? - for instance, wait for “username: ” before sending the username.
Logging, debugging, and safe execution
You want to add logger to your script so how can you send logging messages to the /var/log/messages for your script “*MyCoolScript*”?
Now to write to the messages file, you can use the logger tool which is the syslogd api and send log messages -
logger -t MyCoolScript Starting Application….
You have a bash script that does not produce the expected result so how can you debug it?
In order to debug a bash shell script, you need to add “-x” to the shell execute line -
“#!/bin/bash -x”
You need to create a backup script called backupMyFiles which will run every hour. How do you ensure the script is not already running and exit with a clear message if a previous run is still active?
To check if your script is currently running in the system - you can do it with ps
#!/bin/bash
cmd=namedScript
runningProcs=`ps --no-headers -C${cmd}`
count=`echo $runningProcs|wc -l`
if [ $count -gt 1 ]; then
echo "Previous $cmd is still running."
exit 1
fi
File permissions and validation scripts
Write a shell script that checks if a file (as an argument) has write permissions and accordingly if it is available print “*write access approved*” else print “*no write access*”.
Write a script that receives one parameters (file name) and checks if the file exists or not - If it does, print “*Roger that!*” else, print “*Huston we’ve got a problem!*”
Write a script that checks if a file, given as an argument, has more than 10 lines or not, if it does - print “*Over 10*”, else print “*Less than 10*”
cat $1 | wc -l
if [ "$count" -gt "10" ] ;
then
echo "Over 10"
else
echo "Less than 10"
fiUsers, processes, and system introspection
You have a regular user access to a server, with no root permissions, but you need to create a script that requires root permissions to run - how can you manipulate the system to think that you have root permissions, without a real superuser access?
Write a script that goes over all users on the system and prints each user last login date, or No data for that user when last login is unknown.
cat /etc/passwd | awk -F: '{print $1; }' ;
do
last=last $i | head -n 1;
if [ "$last" != "" ];
then
echo last $i | head -n 1;
else
echo "No data for $i"
fi
doneHow can you check what are the most common commands that you have used in the Linux shell?
You can get this information from the history command and sort it by most used.
$ history | awk '{h[$2]++}END{for (c in h){print h[c] " " c}}' | sort -nr | head
3 history
2 ls
1 hostname
1 cd
Create a script called *KillUserProcs* that will get a username as an input and will kill all his processes.
ps aux|awk -v var=$1 '$1==var { print $2 }'Text processing and one-liners
Using perl, write a command that will print all the IPs, Bcasts and Masks configured on the server line by line.
See also: print all the IPs with ip command.
You need to extract the IPs from the ifconfig first, then run on each line and get the required information -
ifconfig -a | perl -n -l -e '/ addr:([^ ].+)/ and print $1'
Create a Fibonacci function (Fn=Fn-1+Fn-2) using awk (until F20).
Use awk as follows:
awk 'BEGIN { fa=1; fb=1; while(++i<=20) { print fa; ft=fa; fa=fa+fb; fb=ft }; exit}'
Network and utility scripts
Write a script that goes to the Whatismyip website and then prints Your IP is with the result from the site.
Visit whatismyip.org from the script:
#!/bin/sh
ip=links --source http://www.whatismyip.org/
echo -n "Your IP is: "
echo $ip
Create a small calculator in bash script which will have an internal function “*dosomething*” that will receive a math function as an input - mycalc 4+4\*4.
#!/bin/bash function dosomething { echo "${1}"|bc -l; }
dosomething $1
Modern bash practices
Why do teams use set -euo pipefail in bash scripts?
Common safety flags:
-e— exit on first command failure-u— treat unset variables as errors-o pipefail— pipeline fails if any stage fails
Example header:
#!/usr/bin/env bash
set -euo pipefailCombine with explicit trap handlers for cleanup in long-running jobs.
How does ShellCheck help in interviews and on the job?
ShellCheck statically analyzes bash/sh scripts for:
- Quoting bugs and word-splitting traps
- Undefined variables (especially after refactors)
- Deprecated or non-portable constructs
In interviews, mentioning ShellCheck signals you have maintained production cron jobs without silent failures.

