Shell Scripting Interview Questions & Answers part 1
Q: – What is Shell's Responsibilities ?
The shell is responsible for the execution of all programs that you request from your terminal. Each time you type in a line to the shell, the shell analyzes the line and then determines what to do.The line that is typed to the shell is known more formally as the command line. The shell scans this command line and determines the name of the program to be executed and what arguments to pass to the program.
Q: – What is "$#" Variable ?
The $# Variable
Whenever you execute a shell program, the special shell variable $# gets set to the number of arguments that were typed on the command line.
Q: – Explain "Exit Status" for a shell script ?
Whenever any program completes execution under the Unix system, it returns an exit status back to the system. This status is a number that usually indicates whether the program successfully ran. By convention, an exit status of zero indicates that a program succeeded, and nonzero indicates that it failed. Failures can be caused by invalid arguments passed to the program, or by an error condition detected by the program. For example, the cp command returns a nonzero exit status if the copy fails for some reason (for example, if it can't create the destination file), or if the arguments aren't correctly specified (for example, wrong number of arguments, or more than two arguments and the last one isn't a directory). In the case of grep, an exit status of zero (success) is returned if it finds the specified pattern in at least one of the files; a nonzero value is returned if it can't find the pattern or if an error occurs (the arguments aren't correctly specified, or it can't open one of the files).
Q: – What is "Command Substitution" ?
Command substitution is the process by which the shell runs a command and replaces the command substitution with the output of the executed command. That sounds like a mouthful, but it's pretty straightforward in practice.
Q: –What is " eval" command ?
The eval command exists to supersede the normal command-line substitution and evaluation order, making it possible for a shell script to build up commands dynamically. This is a powerful facility, but it must be used carefully. Because the shell does so many different kinds of substitutions, it pays to understand the order in which the shell evaluates input lines.
Q: –What is awk ?
An awk invocation can define variables, supply the program, and name the input files.
Q: – What is "grep" programe ?
The grep program is the primary tool for extracting interesting lines of text from input datafiles. POSIX mandates a single version with different options to provide the behavior traditionally obtained from the three grep variants: grep, egrep, and fgrep.
Q: – Name a new feature introduced with PHP 5.
PHP 5 introduces (among other things) SQLite support, improved XML support, and a significantly improved object model.
Q: – explain "read" command ?
The read command is one of the most important ways to get information into a shell program:
$ x=abc ; printf "x is now '%s'. Enter new value: " $x ; read x
x is now 'abc'. Enter new value: PDQ
$ echo $x