Shell Scripting Interview Questions and Answers

Thumb

Author

BIQ

Questions

14

Last updated

Jan 9, 2023

Most Frequently Asked Shell Scripting Interview Questions

Here in this article, we will be listing frequently asked Shell Scripting Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q1. Can you separate hard and soft links in shell scripting? How?
Answer

Shell scripting is an effective perspective that uses links to create shortcuts, just Like windows. However, soft connections do not have any particular location, can be Anywhere on the same file system, and are usually related to the file name.

The same file time and hard links are on the same file system.

Hard Links are usually related to nodes with a specific fixed location. For example, let's say you have a file called a.txt. If you create a hard link to a file and then delete the file, you can still access the file using the hard link.

However, if you create a soft link to a file and then delete the file, the file becomes inaccessible through the soft link, and the soft link dangles. This is because hard links increase the reference count of a location, while soft links act as shortcuts (like in Windows).

Q2. Why is a shell script needed?
Answer
  • Keeping repetitive tasks to a minimum.
  • can be used by system executives for procedure backups.
  • adding new functions to the shell.
  • system admin can automate daily tasks.
  • shell script permits you to make your tool.
  • Monitoring the system.
Q3. What do you mean by metacharacters?
Answer

In a data program, metacharacters are particular characters that give information about other characters. In shells, they are called regular expressions. A character, not a letter or a number, is usually considered a metacharacter. Using shell metacharacters, you can group commands, redirect and pipe input/output, put commands in the background, reduce the size of file names, etc.

Q4. What is the shebang line in shell scripting?
Answer

Shell scripts or programs often contain a shebang at the top. In general, the shebang is used to indicate the operating system uses a particular interpreter to process the rest of the file. Here, the symbol '#' is referred to as hash, and "!" is called bang. This generally aids developers in ignoring repeated work.

The engines generally execute scripts; therefore, shebang determines the location of the engine that will be used to run the script.

NOTE: If the skills, experience, Shell scripting interview questions, and personality meet the job's requirements, then there are high chances of Getting a job.

Q5. Write the difference between Bourne Shell and the C shell?
Answer
C Shell Bourne Shell
C shell denoted as CSH Bourne shell denoted as BASH
The c shell family is a typical Programming language The Bourne shell family has a much richer programming language.
C shell programming is easier to learn. Bourne shell programming is difficult to learn.
It was developed by Bill Joy in the late 1970s It was developed by Brian Fox.

NOTE: Shell scripting interview questions help you achieve your goal of getting your dream job. From these sample questions/answers, you can be Prepared yourself in advance to face any query.

Q6. Write the difference between $$ and $!?
Answer

$$ specifies the process ID of the currently running process

$! specifies the process ID of the currently running process. Display process IDs of processes that have recently been back grounded.

Q7. What are the different commands available to check disk usage?
Answer
Df command It shows the amount of disk space used and available on the Linux file system.
Du command It shows the amount of disk space used by the specified files and for each and every subdirectory.
Btrfs fi df/device/ That shows disk space usage information for a btrfs based mount point/file system.

NOTE: All the sample Shell scripting interview questions are essential for preparation for the shell scripting interview. From these sample questions, you can easily face it.

Q8. What are the different blocks of a file system? Explain in brief.
Answer

The core concepts are superblocks, inodes, data, directories, and indirect blocks. The superblock contains information about the entire filesystem. B. Its size (exact information depends on the file system). The inode contains all information about the file except its name.

Q9. What are the three security provisions UNIX provides for a file or data?
Answer
  • Read (r): Read permission allows you to open and read the file's contents.
  • Write (w): Write permission will enable you to edit, delete, or rename the file.
  • Execute (x): A program cannot be run or executed on Unix systems unless the execute permission is set.
Q10. Why would we use CLI over GUI?
Answer

The CLI is preferred by professionals looking for performance and speed. However, the GUI requires navigating through various icons. This makes the GUI slow. But with the CLI, you can use your keyboard to navigate the user interface.

Q11. How to create multiple text files and directories?
Answer

To create multiple files, type all filenames consecutively in one touch command and press Enter. For example, to create "myfile1" and "myfile2" simultaneously, the command would touch myfile1 myfile2.

The Linux/Unix mkdir command allows the user to create or create a new directory. mkdir stands for "make directory." You can also use mkdir to set permissions and simultaneously create multiple directories (folders).

Q12. Write the difference between “=” and “==”.
Answer

'=' is an assignment operator that assigns values on the right to the variable on the left.

The '==' operator checks if the two specified operands are equal.

Q13. How will you pass and access arguments to a script in Linux?
Answer

You can pass arguments, and this is a common practice. It was sent to prevent system errors when executing commands and to ensure smooth script execution. Within the script, the variable $1 refers to the command line's first argument, and $2 to his second argument.

For Example

"The file name: $0."

"The first argument is $1." "The second argument is $2." "The third argument is $3."

Q14. How will you debug a shell script?
Answer

Debugging options available in the bash shell can be turned on and off in various ways. For example, inside the script, you can use the set command or add options to the shebang line. However, an alternative is explicitly specifying debug options on the command line while running the script.