Please enable JavaScript to view the comments powered by Disqus. Top 20 Interview Questions On Shell Scripting In 2020

 

Top 20 Interview Questions On Shell Scripting In 2020

NovelVista

NovelVista

Last updated 19/06/2020


Top 20 Interview Questions On Shell Scripting In 2020

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 an equivalent code in other programming languages. While working on a shell script, you’ll have added advantages like an 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 the Interview questions of Shell Scripting might be? Let’s check that out!

 

1. What is Shell?

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? 

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?

 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?

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?

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 of 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?

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 the filled blocks and their respective counts, the size and location of the inode tables, the disk block map, and usage information, and the size of the block groups can be found in a superblock.

7. What is GUI scripting?

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 it passes through?

A Linux process generally has four stages:

  • Waiting
  • Running
  • Stopped
  • Zombie

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

The break is a simple way to escape out of a loop in progress. 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?

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. 

Q11. How to pass an argument to a script?

Arguments are passed through this command:

#!/bin/sh

ct $1

12. How to use arguments in a Script?

Arguments can be used with the help of this command:

#!/bin/sh

cp $1 $2

13. How to calculate the number of passed arguments?

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?

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?

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?

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?

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/column from each line from a file?

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

#!/bin/sh

awk '{print $3}' $1

19. How to write a function?

#!/bin/sh

function example {

echo "Hello Learner"

}

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

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 the industries. Once you are confident about answering these 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 the 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 20 Agile Scrum Interview Questions For Your Big Breakthrough In 2020
Top 20 Agile Scrum Interview Questions For Your Big Breakthrough In 2020
Top 20 interview questions to prepare for ISO27001 Lead Auditor
Top 20 interview questions to prepare for ISO27001 Lead Auditor
Top 20 Microsoft Azure Questions For Your Next Interview
Top 20 Microsoft Azure Questions For Your Next Interview

About Author

NovelVista Learning Solutions is a professionally managed training organization with specialization in certification courses. The core management team consists of highly qualified professionals with vast industry experience. NovelVista is an Accredited Training Organization (ATO) to conduct all levels of ITIL Courses. We also conduct training on DevOps, AWS Solution Architect associate, Prince2, MSP, CSM, Cloud Computing, Apache Hadoop, Six Sigma, ISO 20000/27000 & Agile Methodologies.

 
 

SUBMIT ENQUIRY

 
 
 
 
 
 
 
 
 

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%
     
  18002122003
 
  
 
  • Disclaimer
  • PRINCE2® is a registered trade mark of AXELOS Limited. All rights reserved.
  • ITIL® is a registered trade mark of AXELOS Limited. All rights reserved.
  • MSP® is a registered trade mark of AXELOS Limited. All rights reserved.
  • DevOps® is a registered trade mark of DevOps Institute Limited. All rights reserved.