I’m doing the following, which basically works.
The script tries to insert some lines into a file to rewrite it.
But it is stripping all blank lines and also all line padding.
The main problem is that it does not process the last line of the file.
I’m not sure why.
while read line; do
<... process some things ...>
echo ${line}>> "${ACTION_PATH_IN}.work"
done < "${ACTION_PATH_IN}"
What can be done to fix this?
readnot to strip leading and trailing whitespace.read -rprevents backslash at EOL from creating a line continuation."$line") to prevent the shell from doing word splitting and globbing on its value.printf '%s\n'instead ofechobecause it is reliable when processing values like like-e,-n, etc.< <(printf '%s\n' "$(cat input)")is an ugly way of LF terminating the contents ofinput. Other constructions are possible, depending on your requirements (pipe instead of redirect from process substitution if it is okay that your wholewhileruns in a subshell).It might be better if you just ensured that it was LF-terminated before processing it.