0
0
Bash Scriptingscripting~10 mins

Default values (${var:-default}) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A:=
B:-
C-
D+
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.
2fill in blank
medium

Complete 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'
A${VAR:-}
B${VAR:=}
C${VAR:-default}
D${VAR:=default}
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.
3fill in blank
hard

Fix 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'
A:=
B-
C:-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which does not handle empty values.
Using ':=' which assigns instead of just printing.
4fill in blank
hard

Fill 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'
AVAR
B:-
C-
DVAR:-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of ':-' which ignores empty values.
Putting the operator before the variable name.
5fill in blank
hard

Fill 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'
AVAR
B${VAR:=
D}
Attempts:
3 left
💡 Hint
Common Mistakes
Not closing the brace in the assignment syntax.
Using ':-' instead of ':=' which does not assign.