ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Bash Shell Scripting Tutorial• 6 min read

Variables, Quoting Rules & Command Substitution

Zero spaces around =, double quotes vs single quotes, and $(command) syntax

Bash variables are untyped strings. Understanding quoting rules is essential to prevent unintended word splitting and globbing bugs.

The Golden Rules of Bash Variables

No Spaces Around =: NAME="Codexia" is valid; NAME = "Codexia" fails with a command not found error!

Double Quotes ("..."): Interpolates variables ("$USER") and escapes special characters.

Single Quotes ('...'): Preserves literal text with ZERO interpolation ('$USER' prints raw $USER).

Command Substitution ($(command)): Captures the standard output of a command into a variable.

Command Substitution and Quoting
#!/usr/bin/env bash

APP_NAME="Codexia API"
HOST=$(hostname)
UPTIME=$(uptime -p)

# Double quotes allow variable interpolation
echo "App '$APP_NAME' running on host: $HOST ($UPTIME)"

# Single quotes treat content strictly as literal text
echo 'Literal text: $APP_NAME will not expand here'
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What is the syntax error in the Bash variable assignment `PORT = 8080`?