UNIX Shell Scripting Interview Questions, Answers, and Explanations: UNIX Shell Certification Review
By Equity Press
4.5/5
()
About this ebook
The Ultimate Reference & Learning Guide for the advanced UNIX Operator
Fluency with a UNIX Shell is mandatory for working within the UNIX operating system. Keeping current, however, can be a challenge. With the UNIX Shell Scripting Interview Guide, you will be sure to be current. Using this book to prepare for a job interview or brush up on a scripting programming language will aid any programmer in acquiring new and applicable skills and knowledge. This book contains a complete reference of common scripting errors, performance tuning examples, and common applications. More than just UNIX documentation and open source rhetoric, this guide explains UNIX Shell Scripting from the perspective of the advanced programmer and administrator so you can be sure to come to any interview prepared.
Key topics include:
Graphical user interfaces for UNIX
Advanced features of Bash, Bourne, and Korn
Common errors and troubleshooting
System monitoring and maintenance
Modern command line shells
Read more from Equity Press
SAP ABAP Objects Interview Questions Rating: 4 out of 5 stars4/565 Interview Questions: Conquer Your Fear and Answer the Toughest Job Interview Questions Rating: 4 out of 5 stars4/5SAP Basis Configuration Frequently Asked Questions Rating: 4 out of 5 stars4/5SAP ECC FI Transaction Codes: Unofficial Certification and Review Guide Rating: 5 out of 5 stars5/5Linux Interview Questions: Open Source Operating Systems Interview Questions, Answers, and Explanations Rating: 5 out of 5 stars5/5Breaking In to SAP HR: Interview Questions, Answers and Explanations Rating: 4 out of 5 stars4/5SAP APO Interview Questions, Answers, and Explanations: SAP APO Certification Review Rating: 2 out of 5 stars2/5SAP MDM Frequently Asked Questions Rating: 5 out of 5 stars5/5Microsoft Sharepoint Interview Questions: Share Point Certification Review Rating: 5 out of 5 stars5/5Microsoft NAV Interview Questions: Unofficial Microsoft Navision Business Solution Certification Review Rating: 1 out of 5 stars1/5Adobe Fireworks Web Design Interview Questions: Web Design Certification Review with Adobe Fireworks Rating: 0 out of 5 stars0 ratingsInformation Technology Jobs: Secrets to Landing Your Next Job in Information Technology Rating: 0 out of 5 stars0 ratingsMicrosoft® CRM Interview Questions: Unofficial Microsoft DynamicsTM CRM Certification Review Rating: 3 out of 5 stars3/5AJAX Interview Questions, Answers, and Explanations: AJAX Certification Review Rating: 0 out of 5 stars0 ratingsLotus Domino Interview Questions, Answers, and Explanations: Lotus Domino Certification Review Rating: 0 out of 5 stars0 ratingsMicrosoft Visual Basic Interview Questions: Microsoft VB Certification Review Rating: 0 out of 5 stars0 ratings
Related to UNIX Shell Scripting Interview Questions, Answers, and Explanations
Related ebooks
Linux Commands By Example Rating: 5 out of 5 stars5/5UNIX Shell Programming Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsWork with the Command-line: To Manage Files and Directories in Ubuntu Rating: 5 out of 5 stars5/5Simply Linux: Basics Rating: 5 out of 5 stars5/5Learning Linux Shell Scripting Rating: 4 out of 5 stars4/5The Linux Command Line Beginner's Guide Rating: 4 out of 5 stars4/5Linux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsPowerShell: A Beginner's Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Vim: The Basics Rating: 1 out of 5 stars1/5Arch Linux: Fast and Light! Rating: 3 out of 5 stars3/5Linux Bible Rating: 0 out of 5 stars0 ratingsLinux for Beginners: Linux Command Line, Linux Programming and Linux Operating System Rating: 4 out of 5 stars4/5Linux Essentials - A Beginner's Guide To Linux Operating System Rating: 3 out of 5 stars3/5Let's Use BASH on Windows 10! Rating: 0 out of 5 stars0 ratingsRHCSA Exam Pass: Red Hat Certified System Administrator Study Guide Rating: 0 out of 5 stars0 ratingsPowerShell: A Comprehensive Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Bash for Fun: Bash Programming: Principles and Examples Rating: 0 out of 5 stars0 ratingsLPI Linux Certification Questions: LPI Linux Interview Questions, Answers, and Explanations Rating: 4 out of 5 stars4/5Mastering Shell Commands On Linux Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Easy Linux For Beginners Rating: 2 out of 5 stars2/5Basics with Windows Powershell Rating: 0 out of 5 stars0 ratingsUbuntu Linux Bible Rating: 0 out of 5 stars0 ratingsLinux Shell Scripting Essentials Rating: 1 out of 5 stars1/5The Windows Command Line Beginner's Guide: Second Edition Rating: 4 out of 5 stars4/5Mastering PowerShell: Unleashing the Power of Automation: The IT Collection Rating: 5 out of 5 stars5/5Mastering Linux System Administration Rating: 0 out of 5 stars0 ratingsThe Mac Terminal Reference and Scripting Primer Rating: 4 out of 5 stars4/5
Reviews for UNIX Shell Scripting Interview Questions, Answers, and Explanations
4 ratings1 review
- Rating: 5 out of 5 stars5/5very well explained
Book preview
UNIX Shell Scripting Interview Questions, Answers, and Explanations - Equity Press
BASIC QUESTIONS AND ANSWERS:
Questions most likely to be asked by beginners
Question 01: Shell Script
What is shell script anyway?
A: A shell script, in its most basic form, is simply a collection of operating system commands put into a text file in the order they are needed for execution. Using any of the shells mentioned so far, a text file containing the commands listed in example basic shell script would work every time the script was executed.
Example basic shell script:
#!/bin/sh
rm -f /tmp/listing.tmp> /dev/null 2>&1
touch /tmp/listing.tmp
ls -l [a-z]*.doc | sort> /tmp/listing.tmp
lpr -Ppostscript_1 /tmp/listing.tmp
rm -f /tmp/listing.tmp
Of course, not all scripts are this simple but it does show that ordinary UNIX commands can be used without any extra, fancy scripting constructs. If this script was executed any number of times the result would be the same, a long listing of all the files starting with lower case letters and ending with a doc extension from the current directory printed out on your local PostScript printer. Let’s start to look at this in detail starting at the beginning.
In the Beginning:
The first line of any script should always look a bit like the top line in the example basic shell script; the only difference would be the path leading to the shell executable file, in this case the /bin/sh part. By default, the UNIX system will attempt to execute an ASCII text file
if the files name is supplied as the first argument on the command line. UNIX will attempt to execute the file in the current shell and try to process the included command strings within the file using the syntax rules of the current shell. So, if you are using the Bourne Shell as your default environment and the ASCII file contains a list of UNIX command structures formatted how the Bourne Shell likes them to be formatted, all will work fine. However, if you try and execute a C Shell file with a different syntax structure, the Operating System will complain about unrecognized commands and syntax errors. The reason is no one told the Operating System that it was a C Shell file, so it processed it as a Bourne Shell. The correct way to indicate this to the Operating System is to pass the script name to the shell executable as an argument thus:
user@system$ /bin/csh my_script arg_1 arg_2
However, it didn't take long for someone to notice that this was extra typing that could well be done away with and hence the short hand first line comment was born.
Basically, all comments in shell scripts start with a hash sign (#). However, for the first line only, UNIX reads past the hash to see what's next. If it finds an exclamation point (!), or Bang! as it's known, then what follows is taken as the path to the shell executable binary program. Not only can that, but all the command line arguments that the shell executable allows also be stacked up on this line. With this feature it doesn't matter what flavor of shell your environment is, you can execute a script in any other flavor of shell, as if it was a real UNIX command. Let’s look at the Bourne Shell syntax rules more closely. It would be helpful at this point to print out the sh man pages from your system so that you can compare them with what I have here.
Question 02: Invoking Shell Scripts
How do you invoke shell scripts?
A: There are two ways to invoke a shell script file.
1. Direct Interpretation:
In direct interpretation, the command csh filename [arg ...] invokes the program csh to interpret the script contained in the file filename.
2. Indirect Interpretation:
In indirect interpretation, we must insert as the first line of the file:
#! /bin/csh
or
#! /bin/csh -f
There are situations in which this is not necessary, but it won't hurt to have it and the file must be made executable using chmod. Then it can be invoked in the same way as any other command, i.e., by typing the script file name on the command line.
The -f option says that we want fast startup, which it will achieve by not reading or executing the commands in .cshrc. Thus for example, we won't have the set
values for shell variables or the aliases from that file, but if we don't need them, this will be much faster (if we need a few of them, we can simply add them to the script file