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 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/565 Interview Questions: Conquer Your Fear and Answer the Toughest Job Interview Questions Rating: 4 out of 5 stars4/5SAP FICO Company Creation Rating: 4 out of 5 stars4/5TCP/IP Networking Interview Questions, Answers, and Explanations: TCP/IP Network Certification Review Rating: 5 out of 5 stars5/5Oracle® Financials Interview Questions: Unofficial Oracle Financials Certification Review Rating: 3 out of 5 stars3/5Cisco Network Administration Interview Questions: CISCO CCNA Certification Review Rating: 5 out of 5 stars5/5Oracle Ultimate DBA Interview Questions Rating: 5 out of 5 stars5/5SAPCOOKBOOK Training Tutorials: SAP MM Inventory Management Rating: 4 out of 5 stars4/5SAP Solution Manager Rating: 4 out of 5 stars4/5SAP Security Interview Questions, Answers, and Explanations Rating: 4 out of 5 stars4/5SAP ABAP Objects Interview Questions Rating: 4 out of 5 stars4/5SAP R/3 Transaction Codes Unofficial Certification and Review Guide Rating: 4 out of 5 stars4/5SAP IS-Retail Interview Questions, Answers, and Explanations Rating: 3 out of 5 stars3/5SAP APO Interview Questions, Answers, and Explanations: SAP APO Certification Review Rating: 2 out of 5 stars2/5C# Interview Questions, Answers, and Explanations: C Sharp Certification Review Rating: 5 out of 5 stars5/5COBOL Programming Interview Questions: COBOL Job Interview Preparation Rating: 5 out of 5 stars5/5Python Interview Questions Rating: 5 out of 5 stars5/5Linux Interview Questions: Open Source Operating Systems Interview Questions, Answers, and Explanations Rating: 5 out of 5 stars5/5The Programmer’s Guide to Microsoft Access Rating: 5 out of 5 stars5/5Unofficial SAP WebDynpro for ABAP Rating: 5 out of 5 stars5/5Oracle Database Security Interview Questions, Answers, and Explanations: Oracle Database Security Certification Review Rating: 0 out of 5 stars0 ratingsBreaking In to SAP HR: Interview Questions, Answers and Explanations Rating: 4 out of 5 stars4/5SAPCOOKBOOK Training Tutorials SAP Financials: Accounts Receivable Rating: 4 out of 5 stars4/5SAP MDM Frequently Asked Questions Rating: 5 out of 5 stars5/5
Related to UNIX Shell Scripting Interview Questions, Answers, and Explanations
Related ebooks
Linux Interview Questions: Open Source Operating Systems Interview Questions, Answers, and Explanations Rating: 5 out of 5 stars5/5Linux Commands By Example Rating: 5 out of 5 stars5/5Mastering Linux Shell Scripting Rating: 4 out of 5 stars4/5Linux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsSimply 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/5Work with the Command-line: To Manage Files and Directories in Ubuntu Rating: 5 out of 5 stars5/5Linux Shell Scripting Essentials Rating: 1 out of 5 stars1/5Linux for Beginners: Linux Command Line, Linux Programming and Linux Operating System Rating: 4 out of 5 stars4/5Vim: The Basics Rating: 1 out of 5 stars1/5Linux Bible Rating: 0 out of 5 stars0 ratingsUbuntu Linux Bible Rating: 0 out of 5 stars0 ratingsLet's Use BASH on Windows 10! Rating: 0 out of 5 stars0 ratingsLinux Essentials - A Beginner's Guide To Linux Operating System Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5PowerShell: A Comprehensive Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Arch Linux: Fast and Light! Rating: 3 out of 5 stars3/5Mastering Shell Commands On Linux Rating: 0 out of 5 stars0 ratingsThe Windows Command Line Beginner's Guide: Second Edition Rating: 4 out of 5 stars4/5Bash for Fun: Bash Programming: Principles and Examples Rating: 0 out of 5 stars0 ratingsLinux: A Comprehensive Guide to Linux Operating System and Command Line Rating: 0 out of 5 stars0 ratingsPowerShell: A Beginner's Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Mastering PowerShell: Unleashing the Power of Automation: The IT Collection Rating: 5 out of 5 stars5/5LPI Linux Certification Questions: LPI Linux Interview Questions, Answers, and Explanations 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