In: Computer Science
You are given an array as below:
IFS=", " #set IFS to be a comma.
MYARRAY=(101,102,103,105)
Which of the following structure can be used to expand an array?
${MYARRAY[]}
${MYARRAY[?]}
${MYARRAY[@]}
${MYARRAY[!]}
Which of the following is a test statement that can be used with while or if or elif statements?
#Initialized variables are as below
i=0 #variable i initialized to be 0
[$i -lt 10]
{$i -lt 10}
($i -lt 10)
[i -lt 10]
Which of the following variable stores the first
argument given to a shell program command?
#
2
1
3
You executed a command as below on a terminal
$grep -n "hello" myfile.txt
What is the value of exit status variable "?" if the
command returns an empty output?
none
0
1
2
A variable '!' used by a program is used to store the
number of argument to a shell command.
T/F
-f is an operator to check if a regular file exist in a directory. It is used as:
if test -f myfile.txt
then
echo "file exists"
else
echo "file does not exist"
fi
True
False
1.Which of the following structure can be used to expand an array?
Ans:
${MYARRAY[@]} //or you can also use ${MYARRAY[*]}
2.
Which of the following is a test statement that can be used with while or if or elif statements?
#Initialized variables are as below
i=0 #variable i initialized to be 0
Ans:
[$i -lt 10]
3.Which of the following variable stores the first argument given to a shell program command?
Ans: 1
#0 is used to store filename, # is used to count the arguments
4.You executed a command as below on a terminal
$grep -n "hello" myfile.txt
What is the value of exit status variable "?" if the command returns an empty output?
Ans: 1 #if pattern found, stus code will be 0
5.A variable '!' used by a program is used to store the number of argument to a shell command.
Ans: False. # to store the number of arguments '#' variable is used.
6.f is an operator to check if a regular file exist in a directory. It is used as:
if test -f myfile.txt
then
echo "file exists"
else
echo "file does not exist"
fi
Ans: True