Robert Johns | 22 Jun, 2023

Top 90 Shell Scripting Interview Questions and Answers in 2024

In this article, we share the top 90 shell scripting interview questions in 2024. Whether you want to pursue a career in systems administration, DevOps, data engineering, cybersecurity, or cloud engineering, our list of shell scripting interview questions is the ideal tool for your interview prep.

With wide applications and use cases, shell scripting is still one of the top 6 coding skills among tech professionals in 2024. That’s why our shell scripting interview questions cover the essential topics you need to know, from beginner to pro, including shell scripting coding questions

You can even stack these with some of the best Unix interview questions and Linux interview questions to level up your interview readiness.

Even if you’re brand new to shell scripting, our comprehensive list of interview questions is a fantastic way to test yourself.

Let’s dive in!

Download's Shell Scripting Interview Questions List PDF

Shell Scripting Interview Questions for Beginners 

Let’s get started with some basic interview questions on UNIX shell scripting to get your brain working. I find that these types of UNIX Scripting interview questions are a great way to check that you have first-hand knowledge.

That said, if you’re new to Shell scripting and not sure where to start, we’d highly recommend Jason Cannon’s Shell scripting course on Udemy, as it takes a project-based approach to learn this essential skill.

1. What Is A Shell?

A shell is an interface for users to interact with the operating system (OS), serving as the bridge between a user and the system's kernel. Much like the shell of a nut, it wraps around the inner workings of an OS, allowing you to give instructions via commands, and these are then executed to perform various functions or tasks on the system.

Components of Shell Program

2. What Is Shell Scripting?

Shell scripting is when you write a series of command line instructions within a plain text script file. When you run this script file, it lets the shell execute the commands sequentially, automating tasks that would otherwise be executed one by one, as shown by the example below.


# This shell script greets a user and displays the date and time.

# Get the user's name
echo"Hello! What's your name?"
read name

# Greet the user
echo"Nice to meet you, $name!"

# Display the current date and time
echo"The current date and time is: $(date)"

3. What Is Linux?

Linux is a collection of UNIX-based operating systems that are all open-source and based on the Linux kernel. It's the backbone of many servers, smartphones, and even everyday devices like home routers.

4. What's The Difference Between Unix And Linux?

Unix and Linux share a common architectural design, but Unix is a proprietary OS that’s primarily used for servers and workstations, while Linux is a free and open-source Unix-like system that’s used for a wide array of devices.

5. What Is A CLI?

A CLI (Command Line Interface) is a text-based interface that you can use to interact with software and operating systems. It's like a direct line to the computer's operations, allowing control through the commands you enter.

6. What Is A GUI?

A GUI (Graphical User Interface) allows interaction with digital devices through a series of graphical icons and visual indicators. It also allows you to use mouse or touch gestures to navigate versus typed commands.

7. What Purpose Do Shell Scripts Serve, And Why Are They Important?

Shell scripts can be used to perform repetitive tasks or make your own tools. It's also useful if you're a system admin who wants to automate daily tasks.

Shell scripts are ideal for automating repetitive tasks, increasing your efficiency, and reducing the potential for human error. I think they're crucial because they provide a powerful tool for system administration, batch jobs, and process control.

8. What Program Is Shell Scripting Designed To Be Run By?

Shell scripting is designed to be run by a Shell, a command-line interpreter in an operating system. I would also point out that there are various types of shells, including the Bourne Shell (sh), the Z Shell (zsh), and the Bourne Again Shell (bash) to name a few.

9. What Are The Primary Types Of Shells Available For Use?

The most widely recognized Shells are probably the Bourne Shell (sh), the C Shell (csh), the Korn Shell (ksh), the Bourne Again Shell (bash), and the Z Shell (zsh).

10. What Is A Kernel?

A kernel is the core component of an OS as it functions as the critical bridge between software applications and physical hardware. This means that it manages hardware resources, memory, file systems, and process handling.

Kernel Architecture

11. What Is An Interpreter?

An interpreter is a type of program that executes other programs. I like to describe this as a translator, reading the source code line by line, converting each instruction into machine code, and then immediately executing it, enabling real-time interaction between the user and the code.

12. What Is A Compiler?

A compiler is a program that translates your code from a high-level language like C# into low-level machine code or bytecode that’s specific to the target platform. This means a compiler is also like a translator, as it takes your source code and translates it into machine code.

13. How Many States Of a Linux Process Are There?

In Linux, there are typically five process states, including running & runnable, interruptable_sleep, uninterruptable_sleep, stopped, and zombie.

14. Explain The Different Linux Process States.

  • Running & Runnable: The process is actively using the CPU or ready to be scheduled for execution.
  • Interruptible Sleep: The process is waiting for an event, such as I/O completion, and can be interrupted by signals or other processes.
  • Uninterruptible Sleep: The process is waiting for a specific event, typically related to I/O, and cannot be interrupted by signals.
  • Stopped: The process has been stopped, usually by a user or a signal, and is not currently executing. It can be resumed or terminated.
  • Zombie: The process has completed its execution and is now in a transitory state after exiting but before the parent removes it from the process table.

15. What Is A Root User?

The Root user is a superuser or admin account in a Unix-like OS that has the highest level of privileges and permissions. When you are the Root user, you have unrestricted access to files, directories, and system settings, enabling you to perform administrative tasks and make critical changes to the system.

16. What Are Environment Variables?

These are key-value pairs that can affect the behavior of processes and programs. In general, they are predefined or user-defined variables that store information like paths, configuration settings, or user preferences. By being available to programs and scripts, they provide a convenient way to retrieve and modify specific information.

17. What Is A Shell Script Variable?

These are defined in Shell script files that have been written in a language like Bash. You use these to hold various data types like numbers, strings, arrays, and more. These are like variables from any language, and they’re basically containers to hold information for the script to use, enabling dynamic behavior.

18. What Are The Two Types Of Commonly Used Shell Variables?

I like to use this type of question to show that I understand that Shell variables are either system variables (also known as environment variables) or user variables.

  • System variables: Predefined by the OS or the Shell to hold information about the system environment. A very common example is $PATH which contains the list of directories to search for executable programs.
  • User variables: These are defined and assigned values by the user or within Shell scripts. 

19. What Are Positional Parameters?

Positional parameters are special variables in Shell scripting that hold command-line arguments that we can pass to a script or a Shell function. Each positional parameter corresponds to a specific argument provided at the command line, with the first being $1, the second $2, and so on.

20. What Are Metacharacters?

These are special characters or symbols that we can use to perform wildcard matching, indicate redirection, control command execution, and more. I’ve found that metacharacters are invaluable for manipulating and controlling data within the Shell environment. Some of the most used symbols are probably the pipe (|) which is used to connect standard outputs to standard inputs and redirection with (<) and (>).

21. What Are The Primary Advantages Of Using Shell Scripting?

This is a question where I can show that Shell scripting is ideal for simplifying complex tasks, automating repetitive processes, and enhancing productivity. I’d then point out that through my experience, Shell scripting streamlines workflows increases efficiency, and is excellent for providing seamless integration with existing tools, which allows me to accomplish more in less time.

22. What Are The Disadvantages Of Using Shell Scripting?

I would say that Shell scripting is limited in scalability and performance for complex or resource-intensive tasks. It can also be challenging to maintain or debug Shell scripts as the codebase grows, not to mention the fact that it lacks structured programming constructs found with scripting languages like Python or Ruby.

For the most part, Shell scripts are ideal for automating simple tasks and executing system commands, but they can struggle with complex calculations and data processing. Equally, Shell scripts may not be suitable when cross-platform compatibility is important due to variances in OS Shell environments.

23. What Is A File System As It Pertains To Linux/Unix?

This is a method to organize and manage files and directories on a storage device like a hard disk or an SSD. I’d also make mention that it provides a hierarchical structure for users to store, access, and manipulate data by defining rules and protocols for naming, organizing, and accessing files and directories. The file system is also used to control how data is stored, retrieved, and managed via things like permissions and attributes.

24. What Are The Primary Components Of A File System In Linux/Unix?

The primary components of a file system typically include the boot block, super block, inode table, and data blocks. Each of these components plays a crucial role in organizing and managing files and directories within the file system.

25. What's A Superblock?

The Superblock is a data structure in the file system that contains metadata like the file system type, size, status, and other essential parameters. I’d also mention that the Superblock is typically located at a fixed position, and it is interpreted by the Kernel during the initialization, allowing the OS to properly mount and access the file system.

26. What's A Boot Block?

A Boot block is a small portion of a storage device that contains the initial bootloader code. I’d also point out that it serves as the first step in the bootstrapping process, enabling the system to initialize and load subsequent components of the OS and file system.

27. What's An inode Table?

An Inode table is a data structure that’s used by a file system to store files and directory metadata. I’d also mention that it allows the file system to efficiently locate and manage files and directories within the file system hierarchy.

Overall, it’s typically a table or array where each entry corresponds to a specific file or directory. These entries contain file permissions, ownership, timestamps, file size, and pointers to the data blocks' memory locations. 

28. What's A Data Block?

A Data block is a unit of storage in the file system where file and directory content is stored. This represents a fixed amount of space on a storage device. I’d also use this question to mention that the file system tracks mappings between files and data blocks via Inode table entries or other data structures. I’d also point out that multiple data blocks can be allocated for larger files.

29. What Three Editors Are Available In Nearly All Unix Versions?

This is a question that you could use to show your historical knowledge about the battle between Vim and Emacs, although maybe try to avoid restarting a flame war! That said, I’d keep it fairly simple and list Vim (or vi), Emacs, and Nano.

30. What Is The Most Commonly Used Shell?

I’d say that the most commonly used Shell is Bash (Bourne Again SHell) as it’s the default for many Linux distros, and I’d also point out that it’s widely adopted thanks to its compatibility, extensive feature set and scripting capabilities. 

Intermediate Shell Scripting Interview Questions

Now we’re ready for some more challenging UNIX Shell scripting interview questions! By successfully answering these, you can demonstrate to any potential employer that you have a strong foundation in Shell scripting.

31. What Is The Linux/Unix Equivalent To A File Shortcut?

The Linux/UNIX equivalent to a Microsoft Windows file shortcut is a symbolic link or more simply, a symlink. These are a special type of file that acts as a reference (or pointer) to another file or directory. I’d say that these allow you to create a shortcut-style link to a target file or directory, providing a convenient way to access files and directories across different file system locations.

I really like this question, and I’d begin by pointing out the main differences in how they reference and interact with the target file or directory. I’d then expand by showing:

Hard Links: Direct references to an underlying file or directory due to the creation of an additional directory entry that points to the same inode as the original file. These are great ways to create independent file names for the same content, which means changes to the original file are reflected in all hard links. Usefully, hard link(s) can access deleted file content as long as at least one hard link remains.

Soft Links (Symlinks): This is a special type of file that contains a path pointing to the target file or directory. These act as a shortcut or reference to the target rather than directly accessing the inode. If the target file or directory is deleted or moved, the symbolic link becomes broken, and any attempts to access it will fail until the target is restored or relinked.

Difference Between Hard And Soft Links

33. What Command Is Used To Create Files?

By running the touch command followed by the desired file name, you can create a new file with that name in the current directory. If the file already exists, the touch command updates the file's modification timestamp without altering its content.

34. What Command Is Used To Read Files?

By running the cat (short for concatenate) command followed by file name arguments, you can read the contents of the specified files sequentially. This results in the complete content of the files being shown at the terminal.

35. What Command Is Used To Delete Files?

By running the rm command (short for remove) and file names as arguments, you can delete files and directories. I’d also point out that you may need to use options like -i for interactive mode, as this prompts for confirmation before deleting files, or -rf for recursively deleting directories and their contents.

36. What Is The isql Utility?

The isql utility allows you to execute SQL commands and statements interactively or via Shell scripts. It can connect to database servers to execute SQL queries, create or modify DB objects, and manage DB connections. 

I’d also point out that the usefulness of isql depends on the database system, as it’s not a universally standardized tool across all platforms. I’d also say that in some cases, it is better to use the specific command line client for RDBMS like MySQL and PostgreSQL.

37. What's The Purpose Of The Shebang Line?

The shebang line (or hashbang) is a special comment that you add to the beginning of a Shell script file to specify the interpreter or shell to be used for executing the script. For example, the shebang line #!/bin/bash tells the system to execute the script using the Bash shell.

38. What's The Alternative Command For echo?

While echo is a built-in Shell command, printf is an external command that’s commonly available across different Shells and a good alternative for echo in Linux/UNIX.

39. How Does A Shell Script Obtain Input Values?

I’d say that Shell scripts typically obtain input values from three main sources, including command-line arguments, user prompts, and input redirection.

  • Command-line arguments: Accessed with positional parameter variables like $1, $2, etc.
  • User prompts: Shell scripts prompt the user for input during execution.
  • Input redirection: Input values from standard input (stdin) and input redirection.

40. What Does The mkdir Command Do?

You use the mkdir command to create directories in a Linux/UNIX system by providing a directory name argument. I’d also point out that this will be in the current working directory unless you provide a full path.

41. What Command Lists All Files In The Current Directory?

You use the ls command to list all files in the current directory. I’d point out that when you run this command without arguments, it displays files and directories in the current working directory, but you can enhance the output by using optional parameters like -l for more detailed listings or -a to show hidden files.

42. What Does The compress Command Do?

You use the compress command to compress files in Linux/UNIX systems with the Lempel-Ziv-Welch (LZW) algorithm. This reduces the file size and replaces it with a compressed version with a .Z extension.

43. What Is The finger Command?

You use the finger command to retrieve information about user accounts or users that are logged in to a specific system. This provides details like the username, real name, login time, idle time, terminal, and last login status. I’d also mention that the finger command is useful for system administrators to gather user-related information and monitor user activities.

44. What Does The wc Command Do?

You can use the wc command (short for word count) to count the total number of words, characters, and lines within a specified file or input stream. I’d also point out that when you run wc with a file name argument, it displays the number of lines, words, and bytes in the file. 

45. How Can You Find A List Of All Recently Used Commands?

To find a list of all recently used commands, you can use the command history feature in Linux/UNIX systems. This tracks commands that you’ve executed during the current session, and I’d also point out that there are four main ways to do this:

  • The history command: Running history at the terminal displays recently executed commands along with line numbers you can reference to rerun them.
  • Up and Down keys: These keys navigate through your command history one command at a time, and you can press Enter to execute the command.
  • Searching the history: By using Ctrl+R and typing a keyword or portion of a command, the terminal searches your command history to show the most recent command that matches.
  • Accessing the history file: You can typically find your command history in a file which for Bash is located at ~/.bash_history. You can then open a text editor to view your entire command history.

46. Where Are Shell Programs Stored?

I’d use this question to show that Shell programs are another name for Shell scripts and that they can be stored in various locations depending on the use case:

  • User's home directory: User scripts can be placed in a directory like /home/user/scripts or /home/user/bin to allow easy access and execution.
  • System-wide directories: There are predefined system directories where shell scripts can be stored and made available to all users, with common examples being usr/local/bin, /usr/bin, and /usr/sbin.
  • Custom directories: Users or administrators can create custom directories to store shell scripts, depending on the organizational or project requirements. 

I would also mention that to execute a script, the Shell will search for the script in the directories specified in the $PATH environment variable. This means it’s essential to store your scripts in one of those directories or to add your script directory to $PATH.

47. What Are Three File Permissions That Can Be Assigned To Users?

The three file permissions that you can assign to users are:

  • Read (r): This grants the ability to view the file contents.
  • Write (w): This allows the user to modify the file contents, including deleting contents and renaming files.
  • Execute (x): This allows users to execute a file if it is a script or a program. I’d also mention that when referring to directories, this is needed to allow users to access and navigate directory contents.

48. What Are Loops In Shell Scripting?

Loops are used to allow a set of instructions to be repeated multiple times until a specific condition is met. I’d also mention that the two common types of loops in Shell scripting are For and While loops.

49. Which Loop Methods Could You Use In Shell Scripting?

This is a nice question to show that I am aware of the common For and While loop methods, along with two lesser-known looping options:

  • For Loop: This allows you to iterate over a list of items or a range of values and it executes a block of code for each iteration.
  • While Loop: This repeatedly executes a block of code as long as a specified condition remains true, meaning it stops when the condition is false.
  • Until Loop: This is similar to the While loop but continues executing a block of code until a specified condition becomes true.
  • C-style For Loop: Some shells, including Bash, support a C-style For loop, which allows you to specify an initialization, condition, and iteration expression.

50. What Is The ‘s' Permission Bit In A File?

The s permission bit refers to the setuid or setgid permission. This is set on an executable file that enables special behavior during execution. I’d then elaborate on the differences between setuid and setgid:

  • Setuid (suid): If the s bit is set in the owner's permission section (e.g., -rwsr-xr-x), this shows that the executable file will be executed with the permissions of the file owner rather than the user. This allows a user to temporarily acquire elevated privileges while running the program.
  • Setgid (sgid): If the s bit is set in the group's permission section (e.g., -rwxr-sr-x), it indicates that the executable file will be executed with the permissions of the file's group owner. This grants temporary group-level privileges during program execution.

Overall, I’d point out that the setuid and setgid permissions are useful for scenarios where certain programs or scripts need elevated privileges to perform certain operations but that they should be used carefully to avoid security risks.

51. How Would You Determine How Long The System Has Been Running?

By using the uptime command in Linux/UNIX systems, you can display the duration the system has been running along with the current time, number of logged-in users, and system load averages.

52. Why would you use CLI instead of GUI?

With this question, I’d say that the Command-Line Interface (CLI) can be advantageous over a GUI for the following reasons:

  • Efficiency and speed for text-based operations and command execution.
  • Automation and scripting capabilities for repetitive tasks and batch operations.
  • Remote access and management of servers and headless systems.
  • Resource efficiency, consuming fewer system resources.
  • Reproducibility and script portability across different operating systems.

53. What Is The Default Login Shell?

I’d say that the default login Shell refers to the Shell that is automatically assigned to a user when they log into a Linux/UNIX system. I’d also point out that this may vary, but the most common default login Shell is the Bash Shell (Bourne Again SHell).

As a bonus, I’d also mention that you can use the echo $SHELL command to show the current shell for the logged-in user, which might show as /bin/bash if it is, in fact, the Bash Shell.

54. How Can You Change The Default Login Shell?

You can use the chsh command (Change Shell) to change the default login shell for a user. I’d point out that this command requires administrative privileges (root access) or appropriate permissions. 

The general syntax for this is: sudo chsh -s /path/to/newshell username

After you make this change, it can be verified by logging out and logging back in or opening a new terminal session to apply the changes.

55. How Would You Explain The Difference Between BASH And DOS?

I’d start by saying that Bash and DOS are fundamentally different in terms of platform, command interpreter, features, and compatibility. 

  • Bash: Modern command-line shell with advanced scripting capabilities, extensive command-line options, and compatibility with UNIX-like systems. 
  • DOS: Simpler, legacy operating system with limited functionality, basic command interpreter, and primarily associated with older PC platforms.

56. What Is LILO, And What Is Its Purpose?

LILO (short for LInux LOader) is a bootloader that’s used by Linux systems to load the operating system into memory and start its execution. Overall, its purpose is to facilitate the boot process and provide a way to select and load the desired Linux Kernel. 

I’d also mention that this is helpful to allow users to select from multiple installed Linux Kernels or OS during startup, which is useful if you have a multi-boot system.

I’d also point out that, for the most part, LILO has been superseded by newer bootloaders like GRUB (GRand Unified Bootloader), which offer more advanced features and flexibility.

57. What Does The head Command Do?

You use the head command to display the first few lines of a file or input stream. I’d also mention that it defaults to showing the first 10 lines unless you specify a different number using the -n option with your preferred number.

58. What Does The tail Command Do?

You use the tails command to display the last few lines of a file or input stream. I’d also mention that it defaults to showing the last 10 lines unless you specify a different number using the -n option with your preferred number.

59. How Would You Find The Status Of A Process?

I’d say that you have two primary options to find the status of a process in Linux/UNIX:

  • Use the ps command: You can use this without any options to view a snapshot of currently running processes. But if you know the PID of a specific process, you can use ps -p <PID> to check its status.
  • Use the top command: This provides an interactive real-time view of running processes, and it continuously updates the list of processes.

60. What Command Would You Use To Check Memory Status?

You can use the free command to check the memory status in Linux/UNIX systems, including the total amount of physical memory (RAM), used memory, free memory, and memory utilized for buffers and caches. 

I’d also mention that without options, it provides memory stats in bytes, but you can use the -h option to display memory sizes in a human-readable format like MB or GB.

61. What Is The test Command Used For?

You can use the test command in Shell scripting to perform tests and evaluations, which allows you to check conditions, compare values, and evaluate Boolean expressions. I’d also mention that when you evaluate an expression with test, it will return an exit status of 0 for True or 1 for False. 

This is also a great point to state that this can be unintuitive if you are used to seeing 1 for True and 0 for False in other programming settings.

And for extra credit, you can mention that square brackets [ ] are commonly used as a shorthand form for test and that these allow you to perform the same evaluations in a readable manner.

Advanced Shell Script Interview Questions

These UNIX Shell script interview questions are a great way to test you for more advanced knowledge of the Shell, including a range of Bash scripting interview questions, as this is the most commonly used Shell today.

62. What Is The '$#' Code Used For In Shell Scripting?

In Shell scripting, you can use the $# code to find the number of command-line arguments that were passed to a Shell script or a Shell function. 

I’d also mention that this is particularly useful for scripts that need to handle a variable number of arguments, as it allows you to dynamically determine the number of arguments and then alter your script’s functionality.

63. What Is Crontab?

Crontab (short for cron table) is a feature in Linux and UNIX-like operating systems that you can use to schedule recurring tasks or commands to be executed automatically at specified time intervals. 

I’d also mention that Crontab is both the name of the command-line utility to manage scheduling and the name of the configuration file where the scheduled tasks are defined.

64. What Are The Two Types Of Crontab Entry?

I’d say that broadly speaking, there are two types of Crontab file entries, namely User and System: 

  • User Crontab: Each system user can have their own crontab file, known as the user crontab. This file contains entries that define the schedule and commands to be executed for that particular user.
  • System Crontab: This system-wide crontab file applies to all users on the system, and it’s typically located in the /etc directory and named cron.d or cron.daily. This crontab is usually managed by the system admin.

65. What Is The Difference Between0 '$@' And '$*'?

I would explain that both $@ and $* are special variables that you can use to represent all of the command-line arguments passed to a script or a function. I’d then elaborate on how they handle quoted arguments and whitespace differently:

  • $@: This expands into separate arguments, preserving whitespace and treating each argument as a separate entity.
  • $*: This expands into a single string that combines all of the arguments, and it’s separated by the first character of the IFS (Internal Field Separator), which by default is set to a space.

66. When Does The Lifespan Of A Shell Variable End?

With this question, it’s important to mention that the lifespan of a Shell variable depends on its scope and how it’s defined:

  • Local Variables: Defined within a specific scope like a function or script, they’re created when the scope is entered and cease to exist when the scope is exited. 
  • Environment Variables: Broader scope and accessible by any process or Shell session in the same environment, and they persist until they are explicitly unset or the shell session ends.
  • Session Variables: Defined within an interactive shell session and remain active throughout the session. I’d also mention that Shell session variables from one session are not automatically available in other independent sessions.

67. How Can You Compare Strings Within A Shell Script?

With this question, I’d explain that the simplest way to compare Strings is with the shorthand square bracket [] form of the test command and a conditional if statement. 

You would enclose your particular comparison expression within square brackets, and this could be one of several different comparisons.

  • The = operator: You can use this to check if two strings are equal.
  • The != operator: You can use this to check if two strings are not equal.
  • The > and < operators: You can use these to perform lexicographical comparisons to check if one string is greater than or less than the other.
  • The -z operator: You can use this to check if a string is empty.
  • The -n operator: You can use this check if a string is not empty.

68. How Do You Signal The End Of An If Block In A Shell Script?

I’d describe that the end of an if block is signified by the fi keyword. I’d then elaborate to say that this is the reverse spelling of if and that it helps the Shell script interpreter understand that the statements within the if block are complete.

69. Describe Some Debugging Methods For A Shell Script?

There are several methods you can use when debugging a Shell script. I’d then summarize some of the most common debugging techniques:

  • Echo Statements: Placing echo statements strategically throughout your script can track the execution flow by printing variable values at specific points. This scaffolding helps identify errors or unexpected behavior.
  • Shell Tracing: By using the -x option with the Shell interpreter via something like bash -x allows you to print each command before it’s executed. This provides a detailed trace of the script's execution.
  • Error Reporting: Adding set -e or set -o errexit at the beginning of your script causes the script to exit immediately if any command fails, helping identify errors.
  • Variable Inspection: You can inspect the values of variables at specific points by using the set -x command to enable debugging for specific variables.

70. What Is A Weakly-Typed Language?

A coding language that doesn't require you to declare a data type during variable declaration.

I’d explain that a weakly typed language is also known as a loosely typed language and that this is a programming language that allows for flexible variable typing and implicit type conversions. This is the opposite of strongly typed languages that require a variable type to be declared with variable declarations.

71. Which Shell Scripting Language Is Considered Weakly-Typed?

As the most common Shell scripting language on Unix-like systems, Bash is generally considered to be weakly typed because variables do not have explicit type declarations, and they can hold values of different types throughout the script's execution. 

I’d also say that by using dynamic typing, Bash allows for flexibility in variable assignments and implicit type conversions. I’d also mention that while Bash is generally considered to be weakly typed, there are contexts where stricter typing rules can be enforced, such as with arithmetic operations that expect numeric values.

72. What Is The Difference Between '[[$String == "Efg*"]]' And '[[$String == Efg*]]'?

In this question, I’d explain the main difference stems from the use or omission of quotation marks. I’d then elaborate to say that:

  • For the '[[$string == "efg*"]]' expression: Enclosing the pattern "efg*" in double quotation marks indicates the pattern should be treated as a literal string. This means it would perform a string comparison to check if the value of $string is an exact match for the string "efg*".
  • For the '[[$string == efg*]]' expression: The pattern efg* is not enclosed in quotation marks, indicating it should be treated as a wildcard or glob pattern. This means it would perform a pattern matching comparison to check if $string matches the pattern "efg*".

73. How Would You Use The Gunzip Command?

You would use the gunzip command to decompress a file that has already been compressed with the gzip algorithm, as shown by a file extension of .gz. 

I’d also mention that you can use the -c option to write the decompressed content to the standard output without creating a new file. This is a useful technique for piping the decompressed content to another command for further processing.

74. Why Would You Use C-Shell Instead of Bourne Shell?

I’d explain that there are several benefits to using C shell (csh) over Bourne shell (sh):

  • C-like Syntax: This can be advantageous if you’re familiar with C or C++ as it can make C shell's syntax more intuitive.
  • Interactive Features: C shell provides command-line editing, command history, and job control.
  • Shortcuts and Aliases: C shell supports powerful aliasing and shortcut capabilities.
  • Job Control: C shell offers robust job control for managing and controlling multiple processes simultaneously.

75. Which Command Can You Use To Modify File Permissions?

You would use the chmod command to modify file permissions in Unix-like operating systems. I’d also point out that you can make changes by specifying the desired permissions with symbolic or numeric (octal) representations.

76. What Is IFS?

IFS stands for the Internal Field Separator, which is a special Shell variable to determine how the Shell splits the input into fields or tokens. By default, the IFS variable is set to whitespace characters (space, tab, and newline).

I’d then explain that when the Shell encounters these IFS characters while reading input, it splits the input into separate fields based on these delimiters. These fields can then be accessed individually with positional parameters like $1, $2, and so on.

77. What's The Difference Between '$$' And '$!'?

I’d say that $$ represents the process ID (PID) of the current shell or script, while $! represents the PID of the most recently executed background process. 

Put simply, $$ refers to the PID of the current shell or script, while $! represents the PID of the most recently executed background process.

78. What Happens To Your Current Process When You Execute A Command Using exec?

When a command is executed using exec, the current process is replaced with the new command rather than creating a new process. I’d then explain that the exec command effectively replaces the current Shell process with the specified command, resulting in a complete replacement of the process image.

79. How Would You Handle Signals Like SIGINT In A Shell Script With The trap Command?

In a Shell script, signals like SIGINT (generated by pressing Ctrl+C) can be handled using the trap command, as this allows you to define actions or functions that should be executed when a specific signal is received by the script.

80. What Are The Differences Between A Shell Function And A Shell Script? When Would You Use One Over The Other?

From my experience, a Shell function is a block of reusable code within a Shell script that allows for code modularity and reusability. On the other hand, a Shell script is an executable file that can be invoked independently and is more suitable for automating tasks, performing system administration, or running a sequence of commands. 

I would then wrap up by explaining that you can use a Shell function when you want to modularize and reuse code within a script, while a Shell script is ideal for creating standalone executable files for automation or task sequencing.

Technical Shell Scripting Interview Questions

We’ve spent a lot of time talking about Shell scripting, but it wouldn’t be right if we didn’t tackle some actual scripting. In this section, we’ll cover 10 technical Bash interview questions that are designed to test your practical scripting skills. 

To keep it aligned with the rest of our questions, we’ll cover a range of beginner, intermediate, and advanced Shell scripting questions.

81. Write A Shell Script To Print "Hello, World!" On The Terminal.

echo"Hello, World!"

82. Write A Shell Script To Take Two Numbers As Command-Line Arguments And Print Their Sum.

sum=$(( $1 + $2 ))
echo"The sum is: $sum"

83. Write A Shell Script To Display The Current Date And Time.

current_date=$(date +%Y-%m-%d)
current_time=$(date +%H:%M:%S)
echo"Current date: $current_date"
echo"Current time: $current_time"

84. Write A Shell Script To Count The Number Of Lines In A File And Display The Result.

line_count=$(wc -l < "$file")
echo"Number of lines in $file: $line_count"

85. Write A Shell Script To Search For A Specific Word In A File And Display The Line Number Where It Occurs.

grep -n "$word""$file"

86. Write A Shell Script To List All The Files In A Directory And Its Subdirectories Recursively.

find "$directory" -type f

87. Write A Shell Script To Check If A File Exists And If It Does, Make It Executable.

if [ -f "$file" ]; then
chmod +x "$file"
echo"File made executable."
echo"File does not exist."

88. Write A Shell Script To Monitor The Disk Usage Of A Given Directory And Send An Email Notification If It Exceeds A Certain Threshold.

threshold=90 # Disk usage threshold in percentage

usage=$(df -P "$directory" | awk 'NR==2 {print $5}' | tr -d '%')
if [ "$usage" -gt "$threshold" ]; then
echo"Disk usage of $directory exceeded $threshold% threshold." | mail -s "Disk Usage Alert"

89. Write A Shell Script To Automatically Rotate And Compress Log Files Older Than A Specified Number Of Days.

days_threshold=7 # Number of days to keep logs

find "$log_directory" -type f -mtime +"$days_threshold" -exec gzip {} \;

90. Write A Shell Script To Find The Largest And Smallest Numbers In An Array.

numbers=(5 2 9 1 7)
for num in"${numbers[@]}"; do
if [ "$num" -gt "$max" ]; then
if [ "$num" -lt "$min" ]; then
echo"Largest number: $max"
echo"Smallest number: $min"

Final Thoughts

And there you have it! The top 90 Shell scripting interview questions you need to know in 2024 to sharpen your Shell scripting skills and excel in your next interview. 

Whether you're a complete beginner or a seasoned Shell pro, we’ve covered a wide range of Shell scripting interview questions. From BASH to $PATH, Superblocks to Boot blocks, we’ve even covered 10 technical interview questions that require you to create Shell scripts.

So whether your career path leads to systems administration, DevOps, data engineering, cybersecurity, or cloud engineering, our list of Shell script questions is the ultimate resource for your interview preparation.

And even if you're new to Shell scripting, our comprehensive set of interview questions on Shell scripting is an excellent opportunity to test your knowledge while learning. 

Best of luck with your next interview!

Want to feel even more prepared for your next interview? Check out:

The Best Git Interview Questions

People are also reading:

By Robert Johns

Technical Editor for | 15+ Years in Python, Java, SQL, C++, C#, JavaScript, Ruby, PHP, .NET, MATLAB, HTML & CSS, and more... 10+ Years in Networking, Cloud, APIs, Linux | 5+ Years in Data Science | 2x PhDs in Structural & Blast Engineering

View all post by the author

Subscribe to our Newsletter for Articles, News, & Jobs.

I accept the Terms and Conditions.

Disclosure: is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

In this article

Learn More

Please login to leave comments