Operational Shell Scripting Interview Preparation Guide Download PDF
Shell Scripting Interview Questions and Answers will guide us now that a shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. Learn Shell Scripting with this Shell Scripting Interview Questions with Answers guide
30 Shell Scripting Questions and Answers:
Table of Contents:
1 :: How do you write a while loop in shell?
while {condition} do {statement} done
2 :: How does a case statement look in shell scripts?
case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac
3 :: How do you read keyboard input in shell scripts?
read {variable-name}
4 :: How do you define a function in a shell script?
function-name() { #some code here return }
7 :: How do you stop a process?
kill pid
11 :: How do you write a for loop in shell?
for {variable name} in {list} do {statement} done
12 :: What’s a way to do multilevel if-else’s in shell scripting?
if {condition} then {statement} elif {condition} {statement} fi
14 :: How do you do Boolean logic operators in shell scripting?
! tests for logical not, -a tests for logical and, and -o tests for logical or.
15 :: How do you test for file properties in shell scripts?
-s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability
16 :: How do you do number comparison in shell scripts?
-eq, -ne, -lt, -le, -gt, -ge
17 :: What’s the conditional statement in shell scripting?
if {condition} then … fi
18 :: How do you refer to the arguments passed to a shell script?
, and so on. {xtypo_info}$1, $2 and so on. $0 is your script name.{/xtypo_info} is your script name.
19 :: How do you fire a process in the background?
./process-name &
20 :: How do you find out what’s your shell?
echo $SHELL
22 :: How do you search for a string in a directory with the subdirectories recursed?
grep -r string *
24 :: How do you search for a string inside a given file?
grep string filename