Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the value of VAR or 'default' if VAR is empty or unset.
Bash Scripting
echo ${VAR[1]default} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of ':-' which does not check for empty values.
Using ':=' which assigns the default value to VAR.
Using '+' which behaves differently.
✗ Incorrect
The syntax ${VAR:-default} prints VAR if set and not empty; otherwise, it prints 'default'.
2fill in blank
mediumComplete the code to assign 'default' to VAR only if VAR is unset or empty.
Bash Scripting
VAR=[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ':-' which only provides a default for output but does not assign.
Using empty default values which do nothing.
✗ Incorrect
The '${VAR:=default}' syntax assigns 'default' to VAR if it is unset or empty.
3fill in blank
hardFix the error in the code to print 'default' if VAR is unset or empty.
Bash Scripting
echo ${VAR[1]default} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which does not handle empty values.
Using ':=' which assigns instead of just printing.
✗ Incorrect
The correct syntax is '${VAR:-default}' to print 'default' if VAR is unset or empty.
4fill in blank
hardFill both blanks to print VAR if set and not empty, else print 'default'.
Bash Scripting
echo $[1][2]default}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of ':-' which ignores empty values.
Putting the operator before the variable name.
✗ Incorrect
Use '${VAR:-default}' to print VAR if set and not empty, else 'default'.
5fill in blank
hardFill both blanks to assign 'default' to VAR only if VAR is unset or empty, then print VAR.
Bash Scripting
[1]={{BLANK_2}default
echo $} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not closing the brace in the assignment syntax.
Using ':-' instead of ':=' which does not assign.
✗ Incorrect
The code assigns 'default' to VAR if unset or empty using '${VAR:=default}', then prints VAR.