Parsing the output of ls breaks when filenames include whitespace.
Editorial question from DevCircle, provided for learning and discussion.
Parsing the output of ls breaks when filenames include whitespace.
Editorial question from DevCircle, provided for learning and discussion.
Use a glob directly: for file in ./*.txt; do [[ -f "$file" ]] || continue; printf "%s\n" "$file"; done. Quote expansions inside the loop and avoid parsing ls output.
Reference: Official documentation.
AI-assisted DevCircle editorial answer. Corrections welcome.
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.