1. Which of the following is/are allowed in an arithmetic statement involving expr command?
Answers:
Answers:
1. until=1
2. while [ $until -eq 5 ]
3. do
4. echo until cannot be used as a variable name
5. until=`expr $until + 1`
6. done
Answers:
b=
[ -n $b ]
echo $?
[ -z $b ]
echo $?
Answers:
a=300
[ -n $a ]
echo $?
[ -z $a ]
echo $?
Answers:
1. x=10
2. if [ x -ge 2 ]
3. then
4. echo $x
5. fi
Answers:
Answers:
[ ! $x -gt 9 -a ! $y -ne 23 ]
Answers:
x=3
y='[$x -eq 10 ]’
z='[$x -lt 10 ]’
echo x=$x y=$y z=$z
Answers:
Answers:
suite=3
case $suite in
1) echo Diamond ;;
2) echo Spade ;;
3) echo Heart ;;
4) echo Club ;;
esac
Answers:
Answers:
Answers:
[ $x -eq 11 -a $y -ne 89 ]
Answers:
Answers:
for argument in “$*”
do
echo $argument
done
Answers:
Answers:
1. echo enter your name
2. read filename
3. read name < $filename
4. echo $name
Answers:
1. while who | grep aa12 | wc -l
2. do
3. echo false
4. done
Answers:
Answers:
i=1
for [ i -le 10 ]
do
echo $i
i=’expr $i + 1′
done
Answers:
Answers:
1. j=10 k=12
2. if [ $k>=$j ]
3. then
4. k=$j
5. j=$k
6. fi
7. echo $j $k
Answers:
Answers:
i=1 j=1 k=1
while [ $i -lt 10 ]
do
while [ $j -lt 10 ]
do
while [ $k -lt 10 ]
do
echo $i $j $k
k=’expr $k + 1′
break 3
done
j=’expr $j + 1′
done
i=’expr $i + 1′
done
Answers:
Answers:
Answers:
#!/bin/sh
1. a=12.25 b=12.52
2. if [a=b]
3. then
4. echo “na and b are equal”
5. fi
Answers:
for i in ‘a b c d e’
do
echo $i
done
Answers:
i=4 z=12
[ $i = 5 -a $z -gt 5 ]
echo $?
Answers:
terminal=vt100
case $terminal in
vt100) echo Dec terminal;;
vt200) echo Old terminal;;
ansi) echo Commonly used terminal;;
v*) echo vt series terminal;;
*) echo Any terminal;;
esac
Answers:
Answers:
while [ $1 -gt 10 -a ($2 -o -w $3 ) ]
Answers:
Answers:
Answers:
Answers:
Answers:
set -3 + 1
Answers:
Answers:
Answers:
Answers:
1. j=1
2. while [ $j -le 10 ]
3. do
4. echo $j
5. j = j + 1
6. done
Answers:
for argument in $*
do
echo $argument
done
Answers:
for i in a b c d e
do
echo $i
done
Answers:
for argument in *
do
echo $argument
done
Answers:
1. j=10 k=12
2. if test [ $k -ge $j ]
3. then
4. k=$j
5. j=$k
6. fi
7. echo $j $k
Answers:
Answers:
Answers:
1. x=3 y=5 z=10
2. if [ ($x -eq 3) -a ( $y -eq 5 -o $z -eq 10 ) ]
3. then
4. echo $x
5. else
6. echo $y
7. fi
Answers:
echo Enter a directory Name
read dirname
case $dirname in
*) echo any directory name ;;
c*) echo cobol directory name ;;
f*) echo fortran directory name ;;
p*) echo pascal directory name ;;
esac
Answers:
k=35
echo `[ $k -eq 35 ]“[ $k -eq 50 ]`
Answers:
Answers:
exec < test0.sh
exec < test2.sh
exec < test3.sh
read line
echo $line
Answers:
Answers:
- <>
- {}
- ( )
- &&
- %
Answers:
- An alphabet
- An underscore
- A number and an underscore
- An alphabet and an underscore
- A number and a special symbol other than the underscore
1. until=1
2. while [ $until -eq 5 ]
3. do
4. echo until cannot be used as a variable name
5. until=`expr $until + 1`
6. done
Answers:
- Line 1 should be until=$1
- Until cannot be used as a variable name
- There is no error
- Line 4 should be echo “until cannot be used as a variable name”
- Line 4 should be enclosed within { }
b=
[ -n $b ]
echo $?
[ -z $b ]
echo $?
Answers:
- 1 1
- 2 2
- 0 0
- 0 1
- An error will occur
a=300
[ -n $a ]
echo $?
[ -z $a ]
echo $?
Answers:
- 1 2
- 0 2
- 2 3
- 0 0
- 0 1
1. x=10
2. if [ x -ge 2 ]
3. then
4. echo $x
5. fi
Answers:
- There is no error
- Line 4 should be echo x
- Test should be used on line 2 instead of []
- Line 1 should be x={10}
- Line 2 should be if [ $x -ge 2 ]
Answers:
- The condition is tested at the end.
- It is executed as long as the given condition or list of items evaluate to true.
- It cannot test for conditions.
- We cannot use exit statement under until loop.
[ ! $x -gt 9 -a ! $y -ne 23 ]
Answers:
- 0
- 1
- 2
- 3
- 4
x=3
y='[$x -eq 10 ]’
z='[$x -lt 10 ]’
echo x=$x y=$y z=$z
Answers:
- x=3 y=1 z=1
- x=3 y=0 z=0
- x=3 y=3 z=5
- x=3 y=2 z=1
- None of the above
Answers:
- Output of echo statement can be redirected to a file.
- Shell variables are case sensitive.
- Programs written for Bourne shell are compatible with Korn shell.
- expr can handle only integers.
- Comments can be split over multiple lines if each line is preceded by #.
suite=3
case $suite in
1) echo Diamond ;;
2) echo Spade ;;
3) echo Heart ;;
4) echo Club ;;
esac
Answers:
- Diamond
- Spade
- Heart
- Club
- An error will occur
Answers:
- if [ -f xyz ]
- if [ -d xyz ]
- if [ -v xyz ]
- if [ -r xyz ]
- if [ -e xyz ]
Answers:
- It is a decision making construct.
- The group of commands between the then and else forms the if block.
- The else block is optional.
- The indentation is done in the if-then-fi to improve readability.
- The indentation is mandatory otherwise an error will occur on execution.
[ $x -eq 11 -a $y -ne 89 ]
Answers:
- 0
- 1
- 2
- 3
- 4
Answers:
- a=expr $b + $c
- a=`expr $b * $c`
- a=`expr $b * ( $c + $d )`
- a=expr $c * $d
- a=`expr $b * ( $c + $d )`
for argument in “$*”
do
echo $argument
done
Answers:
- An error will occur
- No output will be displayed
- dog
- dog parrot cuckoo
- dog parrot cuckoo
Answers:
- It cannot be used inside a loop.
- It continues the control to the beginning of the loop, bypassing the statements below it, inside the loop.
- It can only be used in a while loop.
- It has to be associated with an if statement.
- It is used with the case construct.
1. echo enter your name
2. read filename
3. read name < $filename
4. echo $name
Answers:
- 1
- 2
- 3
- 4
- There is no error.
1. while who | grep aa12 | wc -l
2. do
3. echo false
4. done
Answers:
- There is no error
- Condition on line 1 is invalid
- Line 3 should be echo “false”
- Line 3 should be enclosed with {}
- Line 3 should be echo {false}
Answers:
- a=’cat file’
- b=100
- c=50
- d = 25
- e=’ls’
i=1
for [ i -le 10 ]
do
echo $i
i=’expr $i + 1′
done
Answers:
- An error will occur
- 1
- 2
- 5
- 10
Answers:
- the script.
- a “for” loop.
- an “if” statement.
- the shell.
- the “case” construct.
1. j=10 k=12
2. if [ $k>=$j ]
3. then
4. k=$j
5. j=$k
6. fi
7. echo $j $k
Answers:
- One cannot declare two variables on line 1
- Statements on lines 4 and 5 must appear with curly braces {}
- On line 2, test should be used instead of []
- There is no error
- On line 2 -ge should be used instead of >=
Answers:
- is used last.
- is used first.
- is unary type i.e. the operators that operate on single operand.
- is binary type i.e. the operators that operate on two operands.
i=1 j=1 k=1
while [ $i -lt 10 ]
do
while [ $j -lt 10 ]
do
while [ $k -lt 10 ]
do
echo $i $j $k
k=’expr $k + 1′
break 3
done
j=’expr $j + 1′
done
i=’expr $i + 1′
done
Answers:
- An error will occur
- 3 4 5
- 2 2 2
- 2 3 4
- 1 1 1
Answers:
- exit from the “for” or “while” loop.
- exit from the “case” construct.
- terminate the execution of a script.
- exit from an “if” statement.
Answers:
- 0
- 1
- -1
- 2
- -2
#!/bin/sh
1. a=12.25 b=12.52
2. if [a=b]
3. then
4. echo “na and b are equal”
5. fi
Answers:
- There is no error
- Variable declaration on line 1 is incorrect
- The statement to be printed with echo on line 4 should be within curly brackets
- fi should be replaced by endif on line 5
- On line 2, [a=b] should be replaced with [ $a -eq $b ]
for i in ‘a b c d e’
do
echo $i
done
Answers:
- An error will occur
- 5
- e d c b a
- a b c d e
- a b c d e
i=4 z=12
[ $i = 5 -a $z -gt 5 ]
echo $?
Answers:
- 0
- 1
- 2
- 3
- 4
terminal=vt100
case $terminal in
vt100) echo Dec terminal;;
vt200) echo Old terminal;;
ansi) echo Commonly used terminal;;
v*) echo vt series terminal;;
*) echo Any terminal;;
esac
Answers:
- Dec terminal
- Old terminal
- commonly used terminal
- vt series terminal
- Any terminal
Answers:
- shift
- readonly
- ls
- unset
- echo
while [ $1 -gt 10 -a ($2 -o -w $3 ) ]
Answers:
- There is no error
- ( ) brackets are to be used instead of []
- {} brackets are to be used instead of []
- One cannot use -gt and -o in the same expression
- One cannot use -o and -w in the same expression
Answers:
- 0
- 1
- 2
- 2.5
- 3
Answers:
- 1
- 2
- -2
- 0
- 0.285
Answers:
- _newvar
- variable
- #regpay
- expr
Answers:
- a=`ls`
- b=`ls -l`
- c=`1972`
- d=`who`
- e=`who | grep aa1`
set -3 + 1
Answers:
- $1 would be -3
- $1 would be 1
- $1 would be –
- $1 would be set
- An error would occur
Answers:
- While executing a shell script, the shell acts as a compiler.
- Variables declared in a shell script can be displayed at the dollar prompt using the set command.
- There is no restriction on the length of a shell variable name.
- Any shell script by default gets executed in the current shell.
- A shell variable cannot hold negative values.
Answers:
- a code generator.
- an assembler.
- an interpreter./li>
- a compiler.
Answers:
- a=
- a= ”
- a= “”
- All of the above.
1. j=1
2. while [ $j -le 10 ]
3. do
4. echo $j
5. j = j + 1
6. done
Answers:
- There is no error
- Line 1 should be j=$1
- Statements on lines 3 and 4 should be between curly brackets
- Line 4 should be echo {$j}
- Line 5 should be j=`expr $j + 1`
for argument in $*
do
echo $argument
done
Answers:
- An error will occur
- dog
- cuckoo
- cuckoo parrot dog
- dog parrot cuckoo
for i in a b c d e
do
echo $i
done
Answers:
- 5
- 1 2 3 4 5
- a b c d e
- e d c b a
- An error will occur
- a b c d e
for argument in *
do
echo $argument
done
Answers:
- An error will occur
- Unix shell scripting
- Unix shell scripting
- shell
- The names of all files in the current directory would be displayed
1. j=10 k=12
2. if test [ $k -ge $j ]
3. then
4. k=$j
5. j=$k
6. fi
7. echo $j $k
Answers:
- There is no error.
- Variable declaration on line 1 is incorrect.
- The variables to be outputted on line 7 should be enclosed within quotes.
- Output will be 10 12 with a warning message in line 2
- fi should be replaced by endif on line 6
Answers:
- while [ $? -eq 0 ]
- while [ $count -le 0.1]
- while [ $1 -gt 10]
- while [ 0 ]
- while $
Answers:
- The positional parameters would be shifted by one position towards left i.e. parameter 1 will have value of parameter 2, parameter 2 will have value of parameter 3 and so on.
- Only the first positional parameter would be shifted to left position.
- All of the positional parameters would be shifted by one position towards right i.e. parameter 2 will have value of parameter 3, parameter 3 will have value of parameter 4 and so on.
- It would result in an error.
1. x=3 y=5 z=10
2. if [ ($x -eq 3) -a ( $y -eq 5 -o $z -eq 10 ) ]
3. then
4. echo $x
5. else
6. echo $y
7. fi
Answers:
- 1 and a warning about line 2 will occur
- 3 and a warning about line 2 will occur
- 5 and a warning about line 2 will occur
- 10 and a warning about line 2 will occur
- An error will occur
echo Enter a directory Name
read dirname
case $dirname in
*) echo any directory name ;;
c*) echo cobol directory name ;;
f*) echo fortran directory name ;;
p*) echo pascal directory name ;;
esac
Answers:
- any directory name
- cobol directory name
- fortran directory name
- pascal directory name
- An error will occur
k=35
echo `[ $k -eq 35 ]“[ $k -eq 50 ]`
Answers:
- 1 1
- 0 0
- 0 1
- An error will occur
- A blank line will result
Answers:
- t = 256 (space on both sides of ‘=’ operator)
- 3.14 * $r * $r = area
- k=`expr a*b`
- tput cup $row $col
exec < test0.sh
exec < test2.sh
exec < test3.sh
read line
echo $line
Answers:
- It would not read any file
- It would read all the files in reverse order
- It would read only the test0.sh
- It would read only test3.sh
No comments:
Post a Comment