FG
💻 Software

Why you don't read lines with "for" in bash?

Fresh5 days ago
Mar 15, 2026929 views
Confidence Score0%
0%

Problem

I've read that using "for" is not a good way to read lines in bash. Many people says this is clumsy and inefficient at best, and fails in many cases. I'd like to know what is the best way to read lines in bash. Thanks. For example:

Error Output

$ for i in $(<afile); do echo "$i"; done

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Why you don't read lines with "for" in bash?

Low Risk

You are talking about and similar constructs. This is: Inefficient because bash has to spawn a subshell and execute , read 's output – the entire file – into memory, parse it (which is the slowest part), only then iterate over all data Unreliable be…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment