mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-13 00:03:05 +08:00
feat(curriculum): create bash scripting quiz (#56424)
Co-authored-by: Naomi the Technomancer <accounts+github@nhcarrigan.com>
This commit is contained in:
co-authored by
Naomi the Technomancer
parent
0214fbf8ae
commit
62eb2bb4b0
+115
-100
@@ -17,439 +17,454 @@ Answer all of the questions below correctly to pass the quiz.
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is a correct shebang line in bash script?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`!#/bin/bash`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`/#!bin/bash`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`/#!/bin/bash`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`#!/bin/bash`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which command would define `MY_VAR` and print it to the console?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`MY_VAR=10; echo MY_VAR`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`$MY_VAR=10; echo MY_VAR`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`$MY_VAR=10; echo $MY_VAR`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`MY_VAR=10; echo $MY_VAR`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How do you declare a numeric variable?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`declare -n MY_VAR=1`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`declare -d MY_VAR=1`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`declare -x MY_VAR=1`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`declare -i MY_VAR=1`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which command would not run a `script.sh` file?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`./script.sh`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`/tmp/script.sh`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`bash script.sh`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`script.sh`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How to view the manual for the `less` command in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`less man`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`less --man`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`man --less`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`man less`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How would you call `print_arguments` to print `a` and `b` to the terminal?
|
||||
|
||||
```bash
|
||||
print_arguments() {
|
||||
echo "Argument 1: $1"
|
||||
echo "Argument 2: $2"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`print_arguments("a", "b")`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`print_arguments(a, b)`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`print_arguments{a, b}`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`print_arguments "a" "b"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How do you initialize an array in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`ARR=["item1" "item2" "item3"]`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`ARR=[["item1" "item2" "item3"]]`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`ARR={"item1" "item2" "item3"}`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`ARR=("item1" "item2" "item3")`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How do you print the third value of an array in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`echo ${ARR[3]}`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`echo $ARR[2]`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`echo $ARR[3]`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`echo ${ARR[2]}`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How do you assign user input to a variable in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`input MY_VAR`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`cin MY_VAR`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`get MY_VAR`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`read MY_VAR`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What will be the permission flags for the `1.txt` file after executing the command `chmod 765 1.txt`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`rwxrwxrwx`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`rwxr-xrw-`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`r-xrw-rwx`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`rwxrw-r-x`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What keyword does the statement `if ... then ...` end with?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`end`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`done`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`stop`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`fi`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What keyword does the statement `for ... do ...` end with?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`end`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`od`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`stop`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`done`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How do you create a comment in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`// comment`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`!comment`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`/* comment`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`# comment`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What line should you add to the beginning of this snippet to create a `for` loop?
|
||||
|
||||
```bash
|
||||
|
||||
do
|
||||
echo $i
|
||||
done
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`for ( int i = 0; i < 10; i++ )`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`for (( int i = 0; i < 10; i++ ))`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`for (( let i = 0; i < 10; i++ ))`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`for (( i = 0; i < 10; i++ ))`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How would you assign the result of the sum of variables `A` and `B` to the variable `C`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`C=$A + $B`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`C=$(( A + B ))`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`$C=$(( $A + $B ))`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`C=$(( $A + $B ))`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What keyword in a loop skips the rest of the current iteration and begins the next iteration?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`break`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`until`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`done`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`continue`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What does the command `echo $?` do?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Prints the value of the last used variable
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Prints the value of the last used arithmetic operation
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Prints the value of the last executed condition
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Prints the exit code of the last executed command
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What value of `MY_VAR` would satisfy the condition `[[ $MY_VAR =~ ^[A-Z]{1}[a-z]+$ ]]` ?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`freeCodeCamp`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`FreeCodeCamp`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`freecodecamp`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`Freecodecamp`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What types of loops exist in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`for`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`for`, `while`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`for`, `while`, `until`, `forEach`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`for`, `while`, `until`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
How do you print all values of an array in bash?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`echo $ARR[@]`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`echo {ARR[@]}`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`echo ${ARR[$@]}`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`echo ${ARR[@]}`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user