Bird
0
0

You want to assign a default value to path only if it is unset or empty, but also want to save the default back to path. Which syntax should you use?

hard🚀 Application Q8 of 15
Bash Scripting - String Operations
You want to assign a default value to path only if it is unset or empty, but also want to save the default back to path. Which syntax should you use?
Apath=${path:-"/usr/local/bin"}
Bpath=${path-"/usr/local/bin"}
Cpath=${path+"/usr/local/bin"}
Dpath=${path:="/usr/local/bin"}
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between :- and :=

    ${var:-default} returns default if unset or null but does not assign it back; ${var:=default} assigns default to var if unset or null.
  2. Step 2: Choose syntax that assigns default back

    Only ${path:="/usr/local/bin"} assigns the default value back to path.
  3. Final Answer:

    path=${path:="/usr/local/bin"} -> Option D
  4. Quick Check:

    Use := to assign default back [OK]
Quick Trick: Use := to assign default value back to variable [OK]
Common Mistakes:
MISTAKES
  • Using :- which does not assign
  • Confusing - with := syntax
  • Using + which is for alternate value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes