5 ms·
> fails if the files referenced by $f contain white spaces or a newline. This is said every time Bash scripting is mentioned. Why people can't get into the h
by kwhitefoot 5y ago
> fails if the files referenced by $f contain white spaces or a newline.
This is said every time Bash scripting is mentioned. Why people can't get into the habit of quoting all variables in Bash is beyond me and the mention of white space makes sense; but how often, if ever, have you encountered a file name that contained a newline?
Most of the Unix tools are line oriented by default anyway and are frequently used to manipulate lists of file names and paths.
- chasil 5y agoIt's safe to omit quotes for POSIX shell variables that are initialized as numeric, and you enforce to remain numeric. All else should be quoted, and newlines can happen, primarily from abuse. Do not trust user input! Calling fopen() on a file with every ASCII character will work on POSIX, as long as it does not contain a null or forward slash (/). Coding defensively means that this does not crash your processing.
- kwhitefoot 5y agoI'm not objecting to quoting; I do it even when the variable contains, or should contain, a number. I was objecting to the knee jerk inclusion of warnings against file names including newlines. Has anyone encountered one in the wild that was not itself an error?