Unix Shell Scripting Interview Questions And Answers

by Nithyanandham, on Sep 11, 2022 1:14:25 PM

Interview Questions (31)

Q1. What is a shell?

Ans: Shell is a interface between user and the kernel. Even though there can be  only one kernel ; a system can have many shell running simultaneously . Whenever  a user enters a command  through keyboard the shell communicates with the kernel  to execute it and then display the output to the user.

Q2. What are the different types of commonly used shells  on a typical linux system?

Ans: csh,ksh,bash,Bourne . The most commonly used and advanced shell used today is “Bash” .

Q3. What is the equivalent of a file shortcut that we have on window on a Linux system?

Ans: Shortcuts are created using “links” on Linux. There are two types of links that can be used namely “soft link” and “hard link”

Q4. What is the difference between soft and hard links?

Ans: Soft links are link to the file name and can reside on different filesytem as well; however hard links are link to the inode of the file and has to be on the same filesytem as that of the file. Deleting the orginal file makes the soft link inactive (broken link) but does not affect the hard link (Hard link will still access a copy of the file)

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

Ans: Arguments can be passed as:

scriptName “Arg1” “Arg2”….”Argn” and can be accessed inside the script as $1 , $2 .. $n

Q6. What is the significance of $#?

Ans: $# shows the count of the arguments passed to the script.

Q7. What is the difference between $* and $@?

Ans: $@ treats each quoted arguments as separate arguments but $* will consider the entire set of positional parameters as a single string.

Q8. Use sed command to replace the content of the file (emulate tac command)

Ans:

Eg: 

Then O/p should be

EFGH
ABCD

Here G command appends to the pattern space,

h command copies pattern buffer to hold buffer

and d command deletes the current pattern  space.

Q9. Given a file,  replace all occurrence of word “ABC” with “DEF” from 5th line till end in only those lines that contains word “MNO”

 

Topics:Interview Questions with Answers

Comments

Subscribe