Last updated 06/12/2023
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!
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.
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:
Ans: A shell script has two types of variables:
Ans: There are two primary kinds of shells that can be used in a typical Linux system:
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.
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.
Ans: GUI is used to control a computer and its applications. GUI scripting can support different applications and heavily depends on the operating system.
Ans: A Linux process generally has four stages:
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.
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.
Ans: Arguments are passed through this command:
#!/bin/sh
ct $1
Ans: Arguments can be used with the help of this command:
#!/bin/sh
cp $1 $2
Ans: The number of passed arguments can be calculated with this command:
#!/bin/sh
echo "Number of Parameters passed:$#"
Ans: To get a script inside a script, you need to use this command:
!/bin/sh
echo "Script Name:$0"
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
Ans: To get the last line from a file using the terminal, you need to use this command:
tail -1 <filename>
Ans: To get the first line from a file using just the terminal, this following command is used:
head -1 <filename>
Ans: To get the 3rd element from each line, we use this command:
#!/bin/sh
awk '{print $3}' $1
Ans: #!/bin/sh
function example {
echo "Hello Learner"
}
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
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 PostApart 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.
* Your personal details are for internal use only and will remain confidential.
ITIL
Every Weekend |
|
AWS
Every Weekend |
|
DevOps
Every Weekend |
|
PRINCE2
Every Weekend |