1. What is expression in awk programming?
a) expression evaluates a value to print, test or pass to a function
b) expression assigns a new value to a variable or field
c) expression evaluates a value to print, test or pass to a function & also assigns a new value to a variable or field
d) none of the mentioned
Answer: c
Clarification: None.
2. Which one of the following is not true?
a) there are 3 types of constant expressions: numeric, string and regular
b) arithmetic operators are used to evaluate expressions
c) assignment expression is an expression that stores a value into a variable
d) comparison expressions does not compare strings for relationship
Answer: d
Clarification: None.
3. All numeric values are represented within awk in
a) double precision floating point
b) integer
c) exponential notation
d) fixed point
Answer: a
Clarification: None.
4. Concatenation is performed by
a) writing expressions next to one another, with no operator
b) conditional operator
c) relational operator
d) matching operator
Answer: a
Clarification: None.
5. The comparison expression “x ~ y” will true if
a) x is not equal to y
b) the string x does not match the regular expression denoted by y
c) the string x matches the regular expression denoted by y
d) none of the mentioned
Answer: c
Clarification: None.
6. What is the output of this program?
-
#! /usr/bin/awk -f
-
BEGIN {
-
print "20"<"9" ? "true":"false"
-
}
a) true
b) false
c) syntax error
d) none of the mentioned
Answer: a
Clarification: The operands of relational operators are converted to, and compared as string if both are not numbers. Strings are compared by comparing the characters of each. Hence 20 is less then 9.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
true
[email protected]:/home/#
7. What is the output of this program?
-
#! /usr/bin/awk -f
-
BEGIN {
-
a=10;
-
b=10;
-
print a==b ? "true":"false"
-
}
a) true
b) false
c) syntax error
d) none of the mentioned
Answer: a
Clarification: None.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
true
[email protected]:/home/#