What is Bash & Why It Matters in Linux-(Part 1/8)
Bash scripting interview questions challenge more Linux candidates than almost any other topic, not because the concepts are complex, but because most people never practice explaining them clearly. It's not about memorizing commands or syntax. It's about answering simple questions with confidence: What is Bash? What does it do? And why is it important in Linux? If you hesitated while answering any of those questions, this article is the perfect place to begin.
I once watched a candidate freeze on exactly that question. Not because they had never written a script before they had. But they had never thought about how to explain it out loud, to someone who was deciding whether to hire them. Knowing how to do something and knowing how to talk about it are two completely different skills. This article covers both.
This is a Level 1 article. It targets candidates with zero to one year of Linux experience preparing for junior sysadmin screens, helpdesk-to-Linux transitions, and entry-level DevOps hiring pipelines. By the end of this, you will know the right answers and you will know how to frame them so they land well under pressure.
Level 1 - Beginner (0-1 Year):
These questions target candidates with under one year of Linux experience. They appear in junior sysadmin screens, helpdesk-to-Linux-admin transitions, and entry-level DevOps hiring pipelines.
What This Article Covers:
Most beginner candidates memorize definitions but cannot connect them to real usage. That gap shows up fast in interviews. This article closes it.
- What bash scripting actually is and why Linux systems rely on it every day
- The foundational concepts interviewers probe at this level and why they pick those topics
- How to answer in a way that sounds like someone who has used these things, not just read about them
If you can explain bash scripting clearly to a hiring manager who knows nothing about it AND to a senior engineer who does, you pass this round. Can you do both right now?
If you are still getting comfortable with the Linux terminal itself, it helps to have a solid foundation before jumping into scripting. The Linux commands for beginners guide on LinuxTeck is a good place to anchor that foundation before you get deep into bash.
What They Ask First: Core Concepts That Separate Prepared from Unprepared
Every technical screen for a beginner Linux role starts somewhere in this territory. These are the questions where interviewers sort the candidates who read a few articles the night before from the ones who have actually spent time in the terminal. They are not trick questions. They are concept checks. The difference between a good answer and an average one is whether you can say why something matters, not just what it is.
Q01. What is a bash script and what is it used for?
A bash script is a plain text file that contains a series of bash commands. When you run it, the shell executes those commands in order, exactly as if you had typed them yourself in the terminal one by one.
On a real Linux system, bash scripts handle the tasks that would otherwise eat your time: automated backups, user account creation, log cleanup, service restarts. Anything repetitive is a candidate for a script.
Interview Signal:
The interviewer is testing whether you understand scripting as a practical tool, not just a concept. A strong answer mentions automation or a real use case. An average answer just says "it runs commands."
Q02. What does the shebang line do and why does every script start with it?
The shebang is the first line of a script, written as #!/bin/bash. It tells the operating system which interpreter to use when running the file. Without it, the system does not know whether to treat the file as a bash script, a Python script, or something else.
In production, scripts get run by cron jobs, automation tools, and other users who may be in a different shell environment. The shebang guarantees that bash always runs your bash script, regardless of what shell the user has set as their default.
Interview Signal:
This tests whether you think about portability. Candidates who only say "it specifies the interpreter" pass. Candidates who mention why it matters in automation or multi-user environments stand out.
Q03. How do you make a bash script executable and then run it?
You use chmod +x scriptname.sh to give the file execute permission, then run it with ./scriptname.sh from the directory where it lives.
The ./ tells the shell to look in the current directory. Without it, the shell searches only the directories listed in your PATH variable and will not find your script unless it is in one of those locations.
Q04. What is the difference between running a script with bash scriptname.sh versus ./scriptname.sh?
Common Mistake:
Most candidates say these do the same thing. They mostly do, but there is one real difference: bash scriptname.sh does not require the file to have execute permission. ./scriptname.sh does. Also, bash scriptname.sh ignores the shebang line entirely and forces bash as the interpreter regardless of what the shebang says.
Fix: When you run with ./scriptname.sh, the kernel reads the shebang and uses that interpreter. When you run with bash scriptname.sh, you are calling bash directly and the shebang is irrelevant.
For most beginner scripts these behave identically. But in environments where scripts use a different shebang, or where permission controls matter, the distinction is real.
Q05. How do you add a comment inside a bash script?
Any line that starts with a # character is a comment. Bash ignores it completely during execution. The shebang on line one is actually an exception to this because the kernel reads it before bash takes over.
Comments are not optional in production scripts. A script that runs perfectly but has no comments becomes a debugging nightmare six months later when someone else needs to modify it at two in the morning.
Q06. What is a variable in bash and how do you declare one?
A variable stores a value you want to reuse. You declare it without spaces: NAME="linuxteck". You read it back with a dollar sign: $NAME or ${NAME}.
Spaces matter here. NAME = "linuxteck" with spaces will throw an error because bash interprets it as a command named NAME with arguments. That catches beginners constantly.
Q07. What does echo do in a bash script?
The echo command prints text or the value of a variable to standard output. It is one of the most used commands in scripting for displaying messages, logging output, and debugging.
In real scripts, echo is often redirected to a log file instead of printing to screen, which is how automated scripts create their own audit trail. If you want to go deeper on how echo works inside scripts, the guide on using echo in shell scripts covers the practical patterns well.
Q08. What is the difference between single quotes and double quotes in bash?
Double quotes allow variable expansion and command substitution. Single quotes treat everything literally and suppress all expansion.
If you write echo "$USER", bash replaces $USER with the actual username. If you write echo '$USER', the output is the literal string $USER. This difference causes real bugs when people use single quotes expecting variable values and get the variable name instead.
Interview Signal:
This is a classic beginner trap question. Interviewers use it to find out whether you have actually run scripts or just read about them. A candidate who can give a concrete example of when each is appropriate is someone who has hit this bug firsthand.
Q09. How do you read input from the user inside a bash script?
Use the read command. It pauses the script, waits for the user to type something and press Enter, then stores that input in the variable you specify.
Example: read -p "Enter your name: " USERNAME prompts the user and stores their answer in USERNAME. The -p flag lets you put the prompt text on the same line as the cursor, which looks cleaner than echoing first and reading separately.
Q10. What does exit code 0 mean and what does a non-zero exit code mean?
Exit code 0 means the command or script completed successfully. Any non-zero exit code means something went wrong. The specific number gives more detail about what kind of failure occurred.
In automated pipelines and cron jobs, exit codes are how the system knows whether to continue or alert. A script that always exits 0 even when it fails silently breaks automation. This is why professional scripts always check exit codes and exit with the right value.
Interview Signal:
At Level 1, just knowing what exit codes mean is enough. But candidates who mention how exit codes are used in automation or how they check them with $? demonstrate the kind of thinking that gets them hired over someone who just memorized the definition.
Reading Scripts Out Loud: Code Questions That Test Real Understanding
Some interviewers skip the definitions entirely and just put a script in front of you. They want to see if you can read bash and understand what is happening without running it. These questions are not about memorizing syntax. They are about being comfortable enough with bash that you can trace through logic and explain it. If you have spent real time in the terminal, these should feel familiar.
LinuxTeck.com
NAME="Linux"
echo "Hello, $NAME"
Q11. What does the script above output and why?
The script outputs: Hello, Linux
The variable NAME is assigned the string "Linux". When echo runs with double quotes, bash expands $NAME to its value before printing. So the output is the expanded string, not the literal characters.
LinuxTeck.com
echo "Script name: $0"
echo "First argument: $1"
echo "Total arguments: $#"
Q12. If you run the script above as ./myscript.sh hello world, what is the output?
The output would be:
First argument: hello
Total arguments: 2
$0 always holds the script name as it was called. $1 is the first argument passed to the script. $# is the count of all arguments. "hello" and "world" are two separate arguments so the count is 2.
LinuxTeck.com
if [ -f /etc/passwd ]; then
echo "File exists"
else
echo "File not found"
fi
Q13. What does the -f flag test for in the script above, and what would you see on a normal Linux system?
The -f flag checks whether a path exists and is a regular file (not a directory or device file). On any standard Linux system, /etc/passwd always exists, so the output would be:
File existence checks like this are foundational. Any script that reads a config file or log should check whether the file is there before trying to open it. Skipping that check causes confusing errors when files are missing.
LinuxTeck.com
for i in 1 2 3; do
echo "Number: $i"
done
Q14. What is the output of the for loop above?
The loop runs three times, once for each value in the list.
Number: 2
Number: 3
The variable i takes each value in turn. The do...done block is the body of the loop. This basic structure is how you automate repetitive tasks across multiple values or files.
Write the Script: Hands-On Questions That Show You Can Actually Do It
Writing questions reveal something that reading questions cannot. They show whether you can structure your thinking and produce working code, not just recognize it when you see it. At Level 1, interviewers are not looking for optimized or elegant scripts. They want to see logical structure: a shebang, variables used properly, output that makes sense. Getting that right is enough to make a strong impression at this stage.
Q15. Write a bash script that prints "Hello, World!" to the screen.
Start with the shebang, then echo the message. Simple and correct wins here.
LinuxTeck.com
echo "Hello, World!"
Every script needs the shebang. Without it, you are depending on the calling environment to interpret the file correctly. Adding it costs nothing and avoids real problems in automated contexts.
Q16. Write a script that accepts a username as an argument and prints a greeting.
Use $1 to capture the first argument. Add a check so the script gives a clear message if nothing was passed.
LinuxTeck.com
if [ -z "$1" ]; then
echo "Usage: $0 <username>"
exit 1
fi
echo "Hello, $1! Welcome to Linux."
The -z flag tests whether a string is empty. Checking for missing arguments and exiting with a non-zero code is basic defensive scripting. It shows the interviewer you think about how a script will behave when someone uses it incorrectly.
Interview Signal:
Adding the argument check is what separates a "just makes it work" answer from a "thinks like a systems person" answer. Interviewers notice when you protect against bad input without being asked.
Q17. Write a script that creates a directory if it does not already exist.
Check for the directory first using -d, then create it only if it is missing.
LinuxTeck.com
DIR="/tmp/mybackup"
if [ ! -d "$DIR" ]; then
mkdir "$DIR"
echo "Directory created: $DIR"
else
echo "Directory already exists: $DIR"
fi
The ! negates the condition. -d checks for a directory. Wrapping the variable in quotes handles paths with spaces safely. This pattern appears constantly in real admin scripts, especially those that set up backup or log directories.
Q18. Write a simple bash script that loops from 1 to 5 and prints each number.
Use a for loop with brace expansion for a clean range syntax.
LinuxTeck.com
for i in {1..5}; do
echo "Count: $i"
done
Brace expansion {1..5} generates a sequence without needing seq or any external tool. Clean and readable. For loops with ranges are used everywhere in admin scripting, from processing numbered files to iterating over server lists.
Q19. Write a script that checks whether a given file exists and prints an appropriate message.
Accept the file path as an argument and use the -f test to check it.
LinuxTeck.com
FILE=$1
if [ -f "$FILE" ]; then
echo "File found: $FILE"
else
echo "File not found: $FILE"
exit 1
fi
Exiting with 1 when the file is missing makes this script composable. If another script calls this one and the file check fails, the calling script can detect the failure and respond. That kind of thinking is what separates a script written for one use from one written to be reliable in a real environment.
Q20. Write a while loop in bash that counts from 1 to 3.
Use a counter variable and increment it inside the loop with arithmetic expansion.
LinuxTeck.com
COUNT=1
while [ $COUNT -le 3 ]; do
echo "Count: $COUNT"
((COUNT++))
done
The -le flag means "less than or equal to." The ((COUNT++)) increments the counter. Without incrementing, the loop runs forever. That is one of the most common beginner bugs and something interviewers watch for.
The Concepts That Catch People Off Guard: Traps, Tricks, and Misconceptions
These are the questions where overconfident candidates drop points. The answers are not complicated. But they rely on knowing bash well enough that you have hit these issues in real life, or studied them carefully enough to understand why the gotcha exists. Pay attention to each one because at least one of these will show up in your interview.
Q21. Is it okay to use spaces around the equals sign when assigning a variable in bash?
Common Mistake:
Most people coming from other languages write NAME = "value" with spaces. In bash, this does not work. Bash interprets NAME as a command, = as the first argument, and "value" as the second. You get a "command not found" error.
Fix: Variable assignment in bash requires no spaces: NAME="value". This is a hard rule with no exceptions.
This trips up people with Python or JavaScript backgrounds most often. The error message is also confusing because it does not say "variable assignment failed." It says the variable name is not a recognized command.
Q22. What does $? contain after a command runs?
$? holds the exit code of the most recently executed command or script. Zero means success. Anything else means failure.
This is how you check whether a command worked inside a script. You run the command, then immediately check $? before running anything else, because the next command will overwrite it.
Interview Signal:
Knowing about $? is basic. Knowing that you must read it immediately after the command before it gets overwritten is the part that shows real scripting experience. Mention both and you separate yourself from candidates who just memorized the variable name.
Q23. What happens if you forget to close an if statement with fi in bash?
Common Mistake:
Candidates sometimes forget that bash if statements are closed with fi, not a closing brace. If you leave it out, bash throws a syntax error and often a confusing one because the error points to the end of file rather than where the fi is missing.
Fix: Every if needs a matching fi. Every for or while needs done. Every case needs esac. Bash uses English-style closers.
These syntax errors are easy to introduce and sometimes hard to find in a longer script. Indenting your code consistently makes them much easier to spot.
Q24. What is command substitution in bash and what are the two ways to write it?
Command substitution lets you capture the output of a command and use it as a value. The modern syntax is $(command). The older syntax uses backticks: `command`.
Example: DATE=$(date +%Y-%m-%d) stores today's date in the variable DATE. This is used all the time in backup scripts, log file naming, and timestamped output.
Q25. What is the difference between $* and $@ in bash?
Both hold all the arguments passed to a script. The difference shows up when they are quoted. "$*" treats all arguments as a single string. "$@" preserves each argument as a separate item.
In practice, almost always use "$@" when you need to loop over or pass along arguments. If any argument contains a space, "$*" will break it incorrectly while "$@" handles it properly.
Interview Signal:
Most candidates either do not know this or give a vague answer. The candidate who says "the difference matters most when arguments contain spaces" and can explain why immediately stands out. This is a question that rewards time actually spent with scripts, not just reading about them.
Q26. What does the -e flag do when used with echo, and why might you avoid it?
The -e flag enables interpretation of escape sequences like \n for newline and \t for tab. Without it, those sequences print literally.
The reason to be cautious: echo -e is not consistent across all systems. On some, it works as expected. On others with a POSIX-only echo, it does not. If you need reliable escape sequence handling in a portable script, printf is the safer choice.
Q27. Can you run a bash script without the execute permission set? How?
Common Mistake:
Many beginners think execute permission is always required to run a script. It is not. You can run a script by passing it directly to the bash interpreter: bash scriptname.sh. This works even if the file is not executable.
Fix: Execute permission is required when you run the script as ./scriptname.sh, because you are asking the OS to execute it directly. When you call bash scriptname.sh, bash reads the file as input. Read permission is enough.
In practice, setting execute permission with chmod +x is the standard approach. But knowing this distinction matters when you encounter a script someone else created without proper permissions.
Q28. What does set -e do at the top of a bash script?
set -e tells bash to exit immediately if any command in the script returns a non-zero exit code. Without it, bash continues to the next line even after a command fails.
This is a very common first line after the shebang in production scripts because it prevents scripts from quietly continuing after an error and doing something destructive with a broken state.
Q29. What does 2>&1 mean when you see it at the end of a command?
This redirects standard error (file descriptor 2) to wherever standard output (file descriptor 1) is currently going. If you are writing output to a log file, adding 2>&1 means errors go to that same log file instead of printing to the terminal.
Without it, your log file gets stdout but errors disappear or go to the terminal. In automated scripts running via cron, those error messages would go nowhere useful. Combining both streams into one log is standard practice.
Q30. What is a shebang for Python versus bash and when does the distinction matter?
A bash script uses #!/bin/bash. A Python script uses #!/usr/bin/env python3 (or the direct path). The distinction matters whenever you are running scripts in an automated environment that does not inspect the extension, because the shebang is the only reliable way the OS knows which interpreter to invoke.
In a Linux admin environment where you have both bash and Python scripts running side by side, mixing up the shebang means the wrong interpreter tries to run the file and fails in confusing ways.
Q31. What does the double bracket [[ ]] syntax offer over the single bracket [ ] in bash conditionals?
Double brackets are a bash extension that adds pattern matching, regex matching with =~, and cleaner handling of strings with spaces. Single brackets are POSIX-compatible and work in all shells.
Double brackets also do not require you to quote variables as aggressively, which reduces certain classes of bugs. For scripts that will only ever run in bash, double brackets are generally the more robust choice.
Q32. What is the purpose of the PATH variable and what happens if a command is not in PATH?
PATH is a colon-separated list of directories the shell searches when you type a command. If you type ls, bash looks through each directory in PATH until it finds an executable named ls.
If a command is not in any of those directories, you get "command not found." This is why running your own scripts requires either putting them in a PATH directory or using ./ to run from the current directory. Understanding PATH also helps you diagnose issues where a tool is installed but not accessible.
Interview Signal:
PATH knowledge shows up in real sysadmin work constantly. Candidates who can explain it clearly and connect it to real troubleshooting demonstrate hands-on thinking.
Q33. What does the chmod command do and what does chmod 755 set?
The chmod command changes file permissions. chmod 755 sets read, write, and execute for the owner (7), and read and execute for group and others (5 each).
This is a standard permission set for scripts and directories. The owner can run and edit the file. Everyone else can run it but not modify it. For a public-facing script or binary, 755 is the typical choice.
Q34. What is the difference between a relative path and an absolute path in a script?
An absolute path starts from the root of the filesystem: /etc/passwd. It works regardless of what directory you are in. A relative path is relative to the current working directory: ./config.txt or ../logs/app.log.
Scripts that use relative paths can break silently when run from a different directory than expected. This is a common source of bugs in cron jobs, where the working directory is often different from what the script author assumed. Using absolute paths in scripts is safer and more predictable.
Q35. What does the grep command do and give a simple example of using it in a script.
grep searches text for lines matching a pattern and prints the matching lines. It is one of the most used commands in bash scripting for filtering output and parsing files.
A basic example: searching the /etc/passwd file for a specific user. If you need a deeper look at how grep integrates into real scripting workflows, the article on how bash uses grep for text processing covers it well.
LinuxTeck.com
USER="root"
if grep -q "^$USER:" /etc/passwd; then
echo "User $USER exists"
else
echo "User $USER not found"
fi
The -q flag makes grep quiet (no output, just exit code). Using it inside an if statement is clean and efficient.
Q36. What is the difference between > and >> when redirecting output in bash?
A single > overwrites the file completely each time. Double >> appends to the file, preserving whatever was already there.
In log-writing scripts, you almost always want >>. Using > in a log script accidentally wipes your entire log every time the script runs. That mistake has caused real production pain for many people.
Q37. What does /dev/null do and when would you redirect output to it?
/dev/null is a special file that discards everything written to it. Redirecting output there silences it completely.
Use it when you want a command to run silently without cluttering the terminal or log. Common in scripts where you run a check and only care about the exit code, not the output: grep -q "pattern" file 2>/dev/null. It also silences error messages for commands that might fail but where the failure is expected and acceptable.
Q38. What is the purpose of the test command and how does it relate to the [ ] syntax?
The test command evaluates conditions and returns an exit code. The [ ] syntax is a shorthand alias for test. They are functionally equivalent.
So if test -f /etc/hosts and if [ -f /etc/hosts ] do the same thing. The bracket syntax is more readable in scripts, which is why it is the one you see in practice. Understanding that [ is actually a command (and needs a space before the closing ]) explains a class of errors beginners hit when they write [condition] without spaces.
Q39. What is an environment variable and how is it different from a regular shell variable?
A regular shell variable is only available in the current shell session. An environment variable has been exported and is available to all child processes spawned by that shell. The export command promotes a shell variable to an environment variable.
This matters in scripting because a child script does not inherit the parent's shell variables unless they have been exported. Scripts that expect a variable to be available and it is not will either error out or use an empty value silently, depending on the script.
Q40. What does the source command (or dot command) do in bash?
The source command (written as source filename or . filename) runs a script in the current shell rather than in a subprocess. Variables set inside the sourced file are available after it finishes, in your current session.
This is how configuration files and shell profile scripts like ~/.bashrc work. When you run source ~/.bashrc, the new settings take effect immediately in your current shell. If you ran it as a normal script with ./bashrc, the changes would only apply to a subprocess and disappear when that subprocess exited.
More Essentials: The Rest of What Interviewers Ask at This Level
Entry-level interviews cover a wide surface area. These questions round out the full picture of what you need to be comfortable with. Some of these are foundational definitions. Others are practical skills you will use in your first week on the job. Getting these right builds the kind of confidence that carries through the rest of the interview.
Q41. What is a function in bash and how do you define one?
A bash function groups reusable commands under a name you can call multiple times. You define it with the function name followed by parentheses and a block wrapped in braces.
LinuxTeck.com
greet() {
echo "Hello, $1!"
}
greet "Admin"
Functions make scripts shorter and easier to maintain. Instead of repeating the same twenty lines in three places, you write them once and call the function. That is how professional scripts are structured.
Q42. What does the case statement do in bash and when would you use it instead of multiple if-elif blocks?
The case statement matches a variable or expression against a list of patterns and runs the matching block. It is cleaner and more readable than a chain of if-elif when you are testing a single variable against multiple fixed values.
If you are writing a script with a menu that accepts options like "start", "stop", "restart", a case statement handles that naturally. The same logic written as if-elif gets long and repetitive fast.
Q43. What is a here document (heredoc) in bash?
A heredoc lets you feed multiple lines of text to a command without creating a separate file. You open it with <<EOF and close it with EOF on its own line.
Common in scripts that generate config files, send formatted emails, or pass blocks of SQL to a database. It keeps the content inline with the script rather than requiring an external template file.
Q44. How do you perform arithmetic in bash?
Use double parentheses for arithmetic: result=$((5 + 3)). This is cleaner than the older expr command and handles standard operators including addition, subtraction, multiplication, division, and modulo.
One important note: bash integer arithmetic only. It does not handle decimal numbers natively. For floating point math you need a tool like bc.
Q45. What does the -z flag test for in a bash conditional?
-z tests whether a string is empty (zero length). -n tests whether a string is non-empty. These are used constantly for validating arguments and variables.
A script that does not check whether required variables are set before using them will either throw confusing errors or silently do something wrong. -z checks are your first line of defense against that.
Q46. What is the pipe character | used for in bash and give a real-world example?
The pipe connects commands so the output of one becomes the input of the next. It is one of the core ideas that makes Linux so powerful for text processing and automation.
Real example: ps aux | grep nginx | grep -v grep shows all running nginx processes without showing the grep command itself. This kind of pipeline is used constantly in monitoring and troubleshooting scripts.
Q47. How do you schedule a bash script to run automatically using cron?
Open the crontab editor with crontab -e. Add a line with the schedule in cron format followed by the full path to your script.
Example: 0 2 * * * /home/admin/backup.sh runs the script at 2 AM every day. Using full paths is critical in cron jobs because cron runs with a minimal environment and often does not have your PATH set the way your interactive shell does. Scripts that work fine manually often fail in cron because of this.
Q48. What is the difference between a subshell and the current shell in bash?
When you run a script or use parentheses ( ), bash creates a subshell: a child process with a copy of the current environment. Changes made inside a subshell do not affect the parent shell.
This is why you cannot change the working directory of your terminal by running cd /somewhere inside a script and having it stick after the script exits. The cd happened in a subshell. The parent shell's directory did not change.
Q49. What does the find command do and give one example of using it in a script?
The find command searches the filesystem for files and directories matching criteria you specify: name, type, age, size, permissions, and more. It is indispensable for maintenance scripts.
A common example is finding and deleting log files older than 30 days: find /var/log/myapp -name "*.log" -mtime +30 -delete. This kind of cleanup script runs in cron jobs on almost every production Linux server. For more on the find command specifically, the find command guide with examples covers the full range of flags and use cases.
Q50. What is bash scripting used for in a real Linux environment, and give three concrete examples?
Bash scripting automates anything a human would otherwise do manually in the terminal. It is the backbone of Linux system administration.
Three concrete examples: First, automated backups that compress directories and copy them to a remote server on a schedule. Second, user provisioning scripts that create accounts, set passwords, assign groups, and create home directories with one command instead of fifteen. Third, monitoring scripts that check disk space, CPU load, or service health and send an alert when something crosses a threshold. These are not academic examples. They run on real servers every day.
Pro Tip:
When an interviewer asks this kind of broad question, frame your answer with specifics. "It automates system tasks" is weak. Naming three concrete, recognizable use cases shows you have actually thought about this in a real context. You do not need to have built all three yourself to know why they exist.
Q51. What is the difference between a hard link and a soft (symbolic) link in Linux?
A hard link points directly to the same inode as the original file. A symbolic link (symlink) points to the file path. Delete the original file and the hard link still works. Delete the original and the symlink breaks.
In scripting, symlinks come up constantly for managing configuration files, versioned binaries, and shared resources. Knowing the difference helps you avoid creating links that silently break when files move or get deleted.
Q52. How would you debug a bash script that is not working as expected?
Start with bash -x scriptname.sh. The -x flag enables trace mode, which prints each command as it executes with the actual values substituted in. You see exactly what bash is doing, line by line.
You can also put set -x at a specific point inside the script to turn tracing on only for the part you are investigating, then set +x to turn it off. Adding echo statements to print variable values at key points is the other common approach when you need something quick without full tracing.
Q53. What is the meaning of a script being idempotent and why does it matter?
An idempotent script produces the same result whether you run it once or ten times. Running it a second time does not create problems, duplicate entries, or undo what the first run did.
This matters because automated scripts often run on schedules or get re-run after failures. A script that creates a user without checking whether that user already exists will error (or worse, corrupt something) on the second run. The directory-creation example earlier shows this principle: check first, act only if needed.
Q54. How do you write output from a script to a log file while also showing it on screen?
Use the tee command. It reads from standard input and writes to both standard output and a file at the same time.
Example: echo "Backup started" | tee -a /var/log/backup.log prints the message to the terminal and appends it to the log file. The -a flag appends instead of overwriting. This pattern is standard in production scripts where you want visibility on screen during a run and a written record after.
Q55. What does the wc command do and how would you use it in a script?
wc counts words, lines, and characters. The most common flag in scripting is -l, which counts lines.
Example use: counting how many lines are in a log file, or counting how many users exist in /etc/passwd with wc -l /etc/passwd. You can also capture the count in a variable: COUNT=$(wc -l < /etc/passwd) and use it in a condition or report.
How Interviewers Actually Score These Answers
Here is the part nobody tells you before a technical interview. The interviewer is not running your answer through a checklist. They are watching how you think. At Level 1, they do not expect you to know everything. What they expect is that you can give a clean, confident answer for the things you do know, and that you handle the things you do not know with honesty rather than guessing out loud.
A 7 out of 10 answer is technically correct but stops there. It defines the thing and moves on. A 9 out of 10 answer connects the definition to why it matters. "A shebang specifies the interpreter" is a 7. "A shebang specifies the interpreter, which matters in automated environments where the default shell might differ from what the script was written for" is a 9. That one extra sentence requires no additional technical knowledge. It just requires thinking about the thing in context rather than in isolation.
The other thing interviewers score at this level is composure when they probe. If they follow up with "what would happen if the shebang was missing?" they are not trying to trap you. They are seeing whether you can extend your thinking one step further. Pause, think it through, answer. A candidate who says "I am not a hundred percent sure but I believe the shell would default to..." and then reasons through it correctly scores higher than one who either freezes or guesses confidently and gets it wrong.
Questions I Get Asked About Bash Interviews All the Time
How detailed should my answers be in a phone screen versus a technical round?
Phone screens are about signal, not depth. Give the correct answer in two or three clear sentences. Show you know the concept and one real application of it. Save the detailed explanation for when they probe further. Technical rounds give you more time, so there you should naturally extend your answer with a concrete example or edge case without waiting to be asked.
Do I need to memorize exact bash syntax or is explaining the concept enough?
At Level 1, syntax recall matters more than at higher levels. Interviewers expect you to know how to write a basic for loop, a simple if statement, and variable assignment without hesitating. For more advanced flags and options, explaining the concept and saying you would verify the exact syntax with a man page is completely acceptable. What they cannot forgive is not knowing whether the tool exists or what it broadly does.
What if I forget the exact flag during a write-it question? Should I say I'd check the man page?
Yes. Say it directly and without apology: "I know grep has a flag for quiet mode that only returns the exit code. I believe it is -q but I would confirm with the man page." This is exactly what a real engineer does. Interviewers who work in production know that nobody has every flag memorized. What they are watching for is whether you know the tool exists, roughly how to use it, and that you verify before deploying. That is the right instinct.
Will they actually ask me to write a script from scratch in an interview at this level?
Sometimes. More often at Level 1 they will give you a partial script and ask you to complete it, or show you a script and ask what it does. Full from-scratch writing tends to show up more in second-round technical interviews. That said, you should absolutely be able to write a basic script from scratch: shebang, variable, if statement, loop, output. If you practice those five building blocks until they feel natural, you will handle whatever they put in front of you.
How do I handle a question I genuinely have no idea how to answer?
Be honest and steer toward what you do know. "I have not worked with that specific feature, but based on how bash handles similar things, I would expect..." shows intellectual honesty and reasoning ability. Guessing confidently and being wrong is worse than admitting a gap and showing you can reason adjacent to it. Interviewers remember the candidates who think clearly under uncertainty. They forget the ones who confidently got things wrong.
Is there anything I should bring up proactively that interviewers want to hear at Level 1?
Yes: show that you think about error handling and real-world usage without being asked. If they ask you to write a script and you add an argument check or a file existence test, that is exactly the kind of initiative they are looking for. It signals that you have thought about what happens when things go wrong, not just when they go right. You do not need to overload the answer. Just one defensive addition goes a long way.
You Are Ready - Here Is What Comes Next
You now have a solid foundation across the concepts that show up in every beginner bash scripting interview. Work through the code questions until writing a basic script feels like reflex, not recall. The official GNU Bash Manual is worth bookmarking for anything you want to go deeper on. When you are ready to move beyond definitions and into real scripting patterns, the bash scripting fundamentals guide is the natural next step.
Related Articles
- Bash Script Exit Codes and Error Handling (Part 5 of 34)
- Bash If Elif Else Statement with Examples (Part 10 of 34)
- Bash For Loop Linux Examples (Part 18 / 34)
- Linux Shell Scripting Command Cheat Sheet
- Bash Quoting Rules for Cleaner Shell Scripts (Part 15 / 34)
Real interview questions for every experience level - from Beginner to Senior Linux Engineer.