Shell Scripting Interview
Questions
Difference between the output of echo ** and echo *
*
echo ** lists all the filenames in the current directory..
echo * * lists all the filenames in the current directory
twice.
The other way of running shell script apart from using
sh command and chmod?
ans:- using ! we can run a shell script
How do you refer to the arguments passed to a shell
script?
$1, $2 and so on. $0 is your script name.
What’s the conditional statement in shell scripting?
if {condition} then … fi
How do you do number comparison in shell scripts?
-eq, -ne, -lt, -le, -gt, -ge
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
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.
How do you find out the number of arguments passed
to the shell script?
$#
What’s a way to do multilevel if-else’s in shell scripting?
if {condition} then {statement} elif {condition} {statement}
fi
How do you write a for loop in shell?
for {variable name} in {list} do {statement} done
How do you write a while loop in shell?
while {condition} do {statement} done
How does a case statement look in shell scripts?
case {variable} in {possible-value-1}) {statement};;
{possible-value-2}) {statement};; esac
How do you read keyboard input in shell scripts?
read {variable-name}
How do you define a function in a shell script?
function-name() { #some code here return }
How does getopts command work?
The parameters to your script can be passed as -n 15
-x 20. Inside the script, you can iterate through the getopts array as
while getopts n:x option, and the variable $option contains the value of
the entered option.
Have a Unix Problem
Unix
Forum - Do you have a UNIX Question?
Unix Books :-
UNIX Programming,
Certification, System Administration, Performance Tuning Reference Books
Return to : - Unix
System Administration Hints and Tips
(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies.
The site www.gotothings.com is in no way affiliated with
or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.
|