I am trying to loop through a directory of text files and combine them into one document. This works great, but the text files contain code snippets, and all of my formatting is getting collapsed to the left. All leading whitespace on a line is stripped.
#!/bin/sh
OUTPUT="../best_practices.textile"
FILES="../best-practices/*.textile"
for f in "$FILES"
do
echo "Processing $f file..."
echo "">$OUTPUT
cat $f | while read line; do
echo "$line">>$OUTPUT
done
echo >>$OUTPUT
echo >>$OUTPUT
done
I am admittedly a bash noob, but after searching high and low I couldn’t find a proper solution. Apparently BASH hates the leading white space in general.
Instead of:
Do this:
(If there’s a reason you need to do things line by line it’d be good to include that in the question.)