Please enable JavaScript to view the comments powered by Disqus. Master Shell Scripting: Top 20 Interview Questions & Answers

 

 

 

 

Top 20 Shell Scripting Interview Questions for Devops

Bernie Deon
Bernie Deon

Last updated 06/12/2023


Top 20 Shell Scripting Interview Questions for Devops

You have heard of shell scripting before, right? 

The shell script is a computer program or command-line interpreter that is specially designed to be run by the Unix shell.

So the best part about writing a shell script is the commands and syntax are exactly similar to those that were directly entered at the command line. The programmers don’t need to switch to a totally different syntax, like they would have done while working with a different language or while using a compiled language.

Writing a shell script happens faster than writing equivalent code in other programming languages. While working on a shell script, you’ll have added advantages like easy program or file selection, quick start, and interactive debugging. A shell script also helps in providing a sequencing and decision-making linkage around existing programs, and for moderately sized scripts, the absence of a compilation step is an advantage.

Now you understand why Shell Scripting is important in the life of a programmer. Hence, it is only obvious that interviewers will love to question you about it. So, what might the Interview questions of Shell scripting be? Let’s check that out!

Interview questions for unix shell scripting

1. What is Shell?

Ans: The shell is a command-line interpreter that translates commands entered by the user while converting them into a language understandable by the kernel. The shell interprets a command typed in at the terminal, and calls the program that you want. 

2. What is a Shell Script? Can you name some of its advantages? 

Ans:  A shell script is a command-containing text-file that contains commands in the order of their execution time. Shell scripts perform several operations like printing text, file manipulation, and program execution.

The two main advantages of shell scripting are:

  • It allows you to develop your own custom OS with relevant features that best suits your needs best.
  • It allows designing software applications according to their respective platforms.

3. What are the different types of variables used in Shell Script?

 Ans:  A shell script has two types of variables:

  • System-defined variables 
  • User-defined variables 

4. What are the different types of commonly used shells on a typical Linux system?

Ans:  There are two primary kinds of shells that can be used in a typical Linux system:

  • Bourne Shell
  • C-Shell

5. How do you create a shortcut in Linux?

Ans:  Creating a shortcut in Linux can be done through the links present in Linux OS:

Hard Link: They are linked to the inode of the file and must be on the same file system as the file. If you delete the original file, it does not affect the hard link.

Soft Link: They are linked to the file name and can belong to a different file system as well. If you delete the original file, the soft link becomes inactive.

6. Tell us something about the Super Block in Shell scripting.

Ans:  A SuperBlock is a program that contains a record of specific file systems.

Characteristics of a particular file system, like block size, the empty and filled blocks and their respective counts, the size and location of the inode tables, the disk block map, usage information, and the size of the block groups, can be found in a superblock.

7. What is GUI scripting?

Ans:  GUI is used to control a computer and its applications. GUI scripting can support different applications and heavily depends on the operating system.

8. What are the various stages of a Linux process that it passes through?

Ans:  A Linux process generally has four stages:

  • Waiting
  • Running
  • Stopped
  • Zombie

9. What is the difference between break and continue commands?

Ans:  The break is a simple way to escape out of a loop in progress. The break command can be used to exit out from any loop, including while and until loops. 

On the other hand, Continue is responsible for the present iteration of the loop to exit, instead of the entire loop.

10. What is the significance of the Shebang line in Shell Scripting?

Ans:  The Shebang line is usually found at the top of the script,e.g. #!/bin/sh. This line provides information about the location of the engine. This engine is usually the one executing the script. 

11. How to pass an argument to a script?

Ans:  Arguments are passed through this command:

#!/bin/sh

ct $1

12. How to use arguments in a Script?

Ans:  Arguments can be used with the help of this command:

#!/bin/sh

cp $1 $2

13. How to calculate the number of passed arguments?

Ans: The number of passed arguments can be calculated with this command:

#!/bin/sh

echo "Number of Parameters passed:$#"

14. How to get script name inside a script?

Ans:  To get a script inside a script, you need to use this command:

!/bin/sh

echo "Script Name:$0"

15. How to check if the previous command was run successfully?

Ans:  To check the success of the previous command you need to use this logic:

#!/bin/sh

var=$?

if var=0
then

echo "Script was Run successfully"

else

echo "Script was unsuccessful"

fi

16. How to get the last line from a file using just the terminal?

Ans:  To get the last line from a file using the terminal, you need to use this command:

tail -1 <filename>

17. How to get the first line from a file using just the terminal?

Ans:  To get the first line from a file using just the terminal, this following command is used:

head -1 <filename>

18. How to get the 3rd element or column from each line from a file?

Ans:  To get the 3rd element from each line, we use this command:

#!/bin/sh

awk '{print $3}' $1

19. How to write a function?

Ans:  #!/bin/sh

function example {

echo "Hello Learner"

}

20. Write down the Syntax for all the loops in Shell Scripting.

Ans:  There are three kinds of loops for Shell Scripting- For Loop, Until loop, and While Loop. Their syntaxes are mentioned below:

For Loop:

for var in word1 word2 ... wordN

do

   Statement(s) to be executed for every word.

done

While Loop:

while command

do

   Statement(s) to be executed if the command is true

done

Until Loop:

until command

do

   Statement(s) to be executed until command is true

done


Conclusion:

For its user-friendly nature, Shell scripting is adored across all industries. Once you are confident about answering the above questions, you’ll have a number of job opportunities handy. Be it a developer, a cloud admin, an AWS architect, Shell Scripting is useful for all professions.

Wonder how shell scripting can be applied to the professions mentioned above? Check out our website, apply for the courses suitable for your career choice, and we will teach you all of it!

Topic Related Post
Top HR Round Interview Questions with Answers 2023
Top 25 Project Management Interview Questions & Answers
Top 25 Frequently Asked Scrum Master Interview Questions for 2023

About Author

Apart from having a quirky way of writing, she has a vast knowledge regarding Data Science and Machine Learning. Her blogs are portrayed in a storytelling format that makes the readers understand the complicated technical parts swiftly. She prefers staying up to date about the new happenings of the tech world and pinning them down in articles to make our readers well aware of it and has been doing a pretty great job in that.

 
 
SUBMIT ENQUIRY

* Your personal details are for internal use only and will remain confidential.

 
 
 
 
 
 
Upcoming Events
ITIL-Logo-BL ITIL

Every Weekend

AWS-Logo-BL AWS

Every Weekend

Dev-Ops-Logo-BL DevOps

Every Weekend

Prince2-Logo-BL PRINCE2

Every Weekend

Topic Related
Take Simple Quiz and Get Discount Upto 50%
Popular Certifications
AWS Solution Architect Associates
SIAM Professional Training & Certification
ITIL® 4 Foundation Certification
DevOps Foundation By DOI
Certified DevOps Developer
PRINCE2® Foundation & Practitioner
ITIL® 4 Managing Professional Course
Certified DevOps Engineer
DevOps Practitioner + Agile Scrum Master
ISO Lead Auditor Combo Certification
Microsoft Azure Administrator AZ-104
Digital Transformation Officer
Certified Full Stack Data Scientist
Microsoft Azure DevOps Engineer
OCM Foundation
SRE Practitioner
Professional Scrum Product Owner II (PSPO II) Certification
Certified Associate in Project Management (CAPM)
Practitioner Certified In Business Analysis
Certified Blockchain Professional Program
Certified Cyber Security Foundation
Post Graduate Program in Project Management
Certified Data Science Professional
Certified PMO Professional
AWS Certified Cloud Practitioner (CLF-C01)
Certified Scrum Product Owners
Professional Scrum Product Owner-II
Professional Scrum Product Owner (PSPO) Training-I
GSDC Agile Scrum Master
ITIL® 4 Certification Scheme
Agile Project Management
FinOps Certified Practitioner certification
ITSM Foundation: ISO/IEC 20000:2011
Certified Design Thinking Professional
Certified Data Science Professional Certification
Generative AI Certification
Generative AI in Software Development
Generative AI in Business
Generative AI in Cybersecurity
Generative AI for HR and L&D
Generative AI in Finance and Banking
Generative AI in Marketing
Generative AI in Retail
Generative AI in Risk & Compliance
ISO 27001 Certification & Training in the Philippines
Generative AI in Project Management
Prompt Engineering Certification
Devsecops Practitioner Certification
AIOPS Foundation Certification
ISO 9001:2015 Lead Auditor Training and Certification
ITIL4 Specialist Monitor Support and Fulfil Certification
Generative AI webinar
Leadership Excellence Webinar
Certificate Of Global Leadership Excellence
ISO 27701 Lead Auditor Certification
Gen AI for Project Management Webinar
Certified Cloud Tester Foundation
HR Business Partner Certification
Chief Learning Officer Certification
Gen AI in Cybersecurity Webinar
Six Sigma Webinar
Gen AI Powered ITSM Webinar
PM Prince2 PMP Webinar
Certified Generative AI Expert
GCP Professional Cloud Architect
GitHub Copilot Training Program
Certified Service Desk Professional
Certified Generative AI in ITSM
Recruitment & Sourcing