fix: replace awk-based .env parsing with read loop to handle values containing spaces - #83
fix: replace awk-based .env parsing with read loop to handle values containing spaces#83amathxbt wants to merge 1 commit into
Conversation
kutluhaneth46
left a comment
There was a problem hiding this comment.
Review
progress.sh was doing export $(cat .env | awk '/=/ {print $1}'), which only exports the key token before the first whitespace and breaks on values containing spaces (and is generally fragile). The while read + KEY=VALUE regex + export "$line" approach is the right fix for this script.
Minor non-blocking notes:
- Values with embedded shell metacharacters still rely on
.envbeing trusted local config (same as before). - Consider
sed 's/\r$//'if anyone ever drops a CRLF.envon Windows.
LGTM for the stated bug.
kutluhaneth46
left a comment
There was a problem hiding this comment.
Review
progress.sh was doing export $(cat .env | awk '/=/ {print $1}'), which only exports the key token before the first whitespace and breaks on values containing spaces (and is generally fragile). The while read + KEY=VALUE regex + export "$line" approach is the right fix for this script.
Minor non-blocking notes:
- Values with embedded shell metacharacters still rely on
.envbeing trusted local config (same as before). - Consider
sed 's/\r$//'if anyone ever drops a CRLF.envon Windows.
Looks correct for the stated bug — thanks.
Bug
progress.shloads.envusingawkfield splitting:awksplits on whitespace by default. This means any.envvalue that contains a space is silently truncated:Additionally:
grep -v '#'strips entire lines containing#anywhere, not just comment lines — it would incorrectly stripSOME_KEY=value#tag|| error_exitguard never fires on parsing errors becauseexportof an empty string list succeeds silentlyexport $(...)with word-split output is fragile: if a value accidentally contains shell metacharacters, it can cause unexpected behaviourFix
Replace the one-liner with a
while readloop that processes the file line-by-line, correctly skipping blank lines and comment lines while exporting each assignment verbatim:This correctly handles:
KEY=value with spaces)|| [ -n "$line" ]condition)