Bash & Shell Scripting (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are the quoting rules in Bash (Double Quotes `""` vs Single Quotes `''`)?
junior LevelCode Examplebash-shellBasic
In Simple Words: The most common source of bugs in shell scripting:
- Single Quotes (
'...'): Literal interpretation. Preserves the literal string value of every character inside; variables ($VAR) and command substitutions are NOT expanded. - Double Quotes (
"..."): Weak quoting. Preserves literal spaces, but allows variable expansion ($VAR), command substitution ($(cmd)), and arithmetic expansion ($((1+1))). - Rule: Always wrap variables in double quotes (
"$filepath") to prevent word splitting and globbing on filenames containing spaces!
bash
name="World"
echo 'Hello $name' # Outputs: Hello $name
echo "Hello $name" # Outputs: Hello World