0% found this document useful (0 votes)
22 views9 pages

Unit 1 Question Bank

Uploaded by

Siddhesh Chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Unit 1 Question Bank

Uploaded by

Siddhesh Chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Unit 1 Question Bank

1. Explain the mount command parameters in detail. Pg. no 139


Ans

2. Explain in detail The Linux File System. Pg. no 97


Ans:
3. Explain in detail the TAR command functions. Pg no. 120
Ans:

4. Explain the bash shell prompt characters in detail.

Ans: The default prompt symbol for the bash shell is the dollar sign ($). This symbol
indicates that the shell is waiting for you to enter text. You can configure the prompt
to provide basic information about your environment. The first example above
shows three pieces of information in the prompt: ■ The username that started the
shell ■ The current virtual console number ■ The current directory (the tilde sign is
shorthand for the home directory)
5. Explain in detail (any 6) ps command GNU parameters in Linux. Pg.
no 132
ans:
5. Explain the TAR command options in detail. Pg no. 121
Ans:
6. Explain the BSD-style parameters in detail. Pg. no 129
Ans:

8. Explain in detail the Directory handling in Linux. Pg. no 110


9. List and explain (any 6) single letter ls command parameters. Pg. no
106
Ans:

10. What are Environment variables? Explain different environment


variables in detail. Pg. no 123, 124. 125

ans: The bash shell uses a feature called environment variables to store information about
the shell session and the working environment. There are two types of environment
variables in the bash shell: ■ Global variables ■ Local variables
global variable: Global environment variables are visible from the shell session, and any
child processes that the shell spawns. Local variables are only available in the shell that
creates them. This makes global environment variables useful in applications that spawn
child processes that require information from the parent process. To view the global
environment variables, use the printenv command.
Local environment variables, as their name implies, can be seen only in the local process in
which they are defined. Don’t get confused though about local environment variables, they
are just as important as global environment variables. In fact, the Linux system also defines
standard local environment variables for you by default.

Unit 2 Question Bank


1. Explain Redirecting Input and Output with example for shell scripting
in Linux. Pg. no 243
OUTPUT REDIRECTION:
The most basic type of redirection is sending output from a command to a file. The bash
shell uses the greater-than symbol for this: command > outputfile Anything that would
appear on the monitor from the command instead is stored in the output file. The redirect
operator created the file test6 and redirected the output from the date command to the test6
file. If the output file already exists, the redirect operator overwrites the existing file with
the new file data. Sometimes, instead of overwriting the file’s contents, you may need to
append output from a command to an existing file, for example if you’re creating a log file
to document an action on the system. In this situation, you can use the double greater-than
symbol (>>) to append data.
INPUT REDIRECTION:
Input redirection is the opposite of output redirection. Instead of taking the output of a
command and redirecting it to a file, input redirection takes the content of a file and redirects
it to a command. The input redirection symbol is the less-than symbol (< ):
command < inputfile
Here’s an example of using input redirection with the wc command: $ wc < test6 2 11 60 $
The wc command provides a count of text in the data. By default it produces three values: ■
The number of lines in the text ■ The number of words in the text ■ The number of bytes in
the text.

2. Explain in details the Linux Exit Status Codes with example. Pg. no
257
Linux provides the $? special variable that holds the exit status value from the last command
that executed. You must view or use the $? variable immediately after the command you
want to check. It changes values to the exit status of the last command executed by the shell
By convention, the exit status of a command that successfully completes is zero. If a
command completes with an error, then a positive integer value is placed in the exit status.
The invalid command returns an exit status of 127. An exit status value of 126 indicates that
the user didn’t have the proper permissions set to execute the command
Linux Exit Status Codes
0:Successful completion of the command
1: General unknown error
2:Misuse of shell command
126: The command can’t execute
127: Command not found
128: Invalid exit argument
130: Command terminated with Ctl-C
255: Exit status out of range

3. Explain the test Numeric Comparison & describe any one comparison
with example. Pg. no 268
ans: The most common method for using the test command is to perform a comparison of
two numeric values. The numeric test conditions can be used to evaluate both numbers and
variables. Here’s an example of doing that:
$ cat test5
#!/bin/bash
# using numeric test comparisons
val1=10
val2=11
if [ $val1 -gt 5 ]
then
echo "The test value $val1 is greater than 5"
fi
if [ $val1 -eq $val2 ]
then
echo "The values are equal"
else
echo "The values are different"
fi
File comparisons: These conditions give you the ability to check files in your filesystem
within your shell scripts The last category of test comparisons is quite possibly the most
powerful and most used comparisons in shell scripting. The test command allows you to test
the status of files and directories on the Linux filesystem. Checking directories:The -d test
checks if a specified filename exists as a directory on the system. Checking if an object exists
The -e comparison allows you to check if a file or directory object exists before you attempt
to use it in your script. Checking for a file: The -e comparison works for both files and
directories. To be sure that the object specified is a file, you must use the -f comparison.
Reading the file: Before trying to read data from a file, it’s usually a good idea to test if you
can read from the file first. This is done using the -r comparison. Checking if you can write
to a file: The -w comparison determines if you have permission to write to a file. Checking if
you can run a file: The -x comparison is a handy way to determine if you have execute
permission for a specific file.

4. Explain in detail (any 6) ‘expr’ command operators.


Ans: The expr command allowed the processing of equations from the command line, but it
is extremely clunky. The expr command recognizes a few different mathematical and string
operators. The 6 expr command operator are:
1. ARG1 < ARG2 Return 1 if ARG1 is less than ARG2; otherwise, return 0
2. ARG1 + ARG2 Return the arithmetic sum of ARG1 and ARG2
3. ARG1 - ARG2 Return the arithmetic difference of ARG1 and ARG2.
4. ARG1 > ARG2 Return 1 if ARG1 is greater than ARG2; otherwise, return 0.
5. length STRING Return the numeric length of the string STRING
6. (EXPRESSION) Return the value of EXPRESSION.

5. Explain The if-then-else statement in detail with example.


Ans: If the command returns a non-zero exit status code, the bash shell just moves on to the
next command in the script. In this situation, it would be nice to be able to execute an
alternate set of commands. If the command in the if statement line returns with an exit status
code of zero, the commands listed in the then section are executed, just as in a normal if-
then statement. If the command in the if statement line returns a non-zero exit status code,
the bash shell executes the commands in the else section.eg.
$ cat test4
#!/bin/bash # testing the else section
testuser=badtest
if grep $testuser /etc/passwd
then
echo The files for user $testuser are:
ls -a /home/$testuser/.b*
else
echo "The user name $testuser doesn’t exist on this system"
fi
$ ./test4 The user name badtest doesn’t exist on this system
$
6. Explain in detail The While command with syntax and example. Pg.
no 299
ans: The while command allows you to define a command to test, then loop through a set of
commands for as long as the defined test command returns a zero exit status. It tests the
test command at the start of each iteration. When the test command returns a non-zero exit
status, the while command stops executing the set of command. Basic while format The
format of the while command is:
while test command
do
other commands
done
eg:

7. Explain The Backtick character with example for shell scripting in


Linux. Pg. no 242

Ans: One of the most useful features of shell scripts is the lowly back quote character,
usually called the backtick (`) in the Linux world. The backtick allows you to assign the
output of a shell command to a variable. While this doesn’t seem like much, it is a major
building block in script programming. The shell runs the command within the backticks,
and assigns the output to the variable testing. Example:

7. Explain Nesting loops in detail with example. Pg. no 304


Ans: A loop statement can use any other type of command within the loop, including
other loop commands. This is called a nested loop. A simple example of nesting a for
loop inside another for loop

8. Explain For loop in detail with example.

ans: the for loop operates on lists of items. It repeats a set of commands for every item in a
list.

Syntax

for var in word1 word2 ... wordN


do
Statement(s) to be executed for every word.
done
eg:

9. Explain in steps of how to create a script file. Pg. no 202


Ans: Let us understand the steps in creating a Shell Script:

1. Create a file using a vi editor(or any other editor). Name script file with extension .sh
2. Start the script with #! /bin/sh
3. Write some code.
4. Save the script file as filename.sh
5. For executing the script type bash filename.sh

You might also like