Unexpected behavior in Bash
Fresh3 days ago
Mar 15, 2026404 viewsConfidence Score0%
0%
Problem
From : So it's perfectly legal to write: but it doesn't work as I expect (it prints just a newline). It's quite strange to me since: Could someone please explain me where I'm doing wrong?
Error Output
foo=bar echo $foo
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Canonical Fix
Unverified Fix
New Fix – Awaiting Verification
Fix for: Unexpected behavior in Bash
Low Risk
This happens because variable expansion is done before the command is run. At the time variable expansion happens, is not set, so it expands to the empty string. The command then runs, setting .
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix