curriculum/challenges/english/blocks/quiz-bash-scripting/66f1afbd9998e9c985d8e73b.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
What is a correct shebang line in bash script?
!#/bin/bash
/#!bin/bash
/#!/bin/bash
#!/bin/bash
Which command would define MY_VAR and print it to the console?
MY_VAR=10; echo MY_VAR
$MY_VAR=10; echo MY_VAR
$MY_VAR=10; echo $MY_VAR
MY_VAR=10; echo $MY_VAR
Which command is used to view all variables in the shell?
declare -n env
declare -p env
declare -x bashrc
declare -p
Which command would run a script.sh file?
script.sh bash
zsh ./script.sh
./sh script.sh
./script.sh
How to view the manual for the less command in bash?
less man
less --man
man --less
man less
How would you call the print_arguments function to print a and b to the terminal?
print_arguments() {
echo "Argument 1: $1"
echo "Argument 2: $2"
}
print_arguments("a", "b")
print_arguments(a, b)
print_arguments{a, b}
print_arguments "a" "b"
How do you initialize an array in bash?
ARR=["item1" "item2" "item3"]
ARR=[["item1" "item2" "item3"]]
ARR={"item1" "item2" "item3"}
ARR=("item1" "item2" "item3")
How do you print the third value of an array in bash?
echo ${ARR[3]}
echo $ARR[2]
echo $ARR[3]
echo ${ARR[2]}
How do you assign user input to a variable in bash?
input MY_VAR
cin MY_VAR
get MY_VAR
read MY_VAR
What will be the permission flags for the 1.txt file after executing the command chmod 765 1.txt?
rwxrwxrwx
rwxr-xrw-
r-xrw-rwx
rwxrw-r-x
What keyword does the statement if ... then ... end with?
end
done
stop
fi
What keyword does the statement for ... do ... end with?
end
od
stop
done
How do you create a comment in bash?
// comment
!comment
/* comment
# comment
What line should you add to the beginning of this snippet to create a for loop?
do
echo $i
done
for ( int i = 0; i < 10; i++ )
for (( int i = 0; i < 10; i++ ))
for (( let i = 0; i < 10; i++ ))
for (( i = 0; i < 10; i++ ))
How would you assign the result of the sum of variables A and B to the variable C?
C=$A + $B
C=$( A + B )
$C=$(( $A + $B ))
C=$(( A + B ))
Which command is used to create a new file?
newfile
echo new_file
fileargs
touch
What does the command echo $? do?
Prints the value of the last used variable.
Prints the value of the last used arithmetic operation.
Prints the value of the last executed condition.
Prints the exit code of the last executed command.
What advantage does Bash provide when testing parts of a script?
Bash scripts must be compiled before testing
You can only test scripts using an IDE
Bash automatically generates test cases
Script sections can be pasted directly into the terminal for testing
What types of loops exist in bash?
for
for, while
for, while, until, forEach
for, while, until
How do you print all values of an array in bash?
echo $ARR[@]
echo {ARR[@]}
echo ${ARR[$@]}
echo ${ARR[@]}