From f207be6671545928b97dcce8fd7e47815402a081 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 30 Nov 2010 19:27:59 -0300 Subject: [PATCH] dsv (setup): make sure file ends with a newline, so that we can "read" it --- dsv/dsv | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/dsv/dsv b/dsv/dsv index aa91ea7..7c2bece 100755 --- a/dsv/dsv +++ b/dsv/dsv @@ -102,20 +102,26 @@ setup() echo "$n: not found" 2>&1 continue fi - while read line; do - [ "$line" = "${line###}" ] || continue - tmp=`echo "$line" | awk '/^[^\t ]/ { print $1 }'` - tail=`echo "$line" | sed 's/^[^\t ]*[\t ]*//'` - if [ -z "$tmp" ]; then - [ -z "$tail" ] || value="$value $tail" - else - set_value - tag=$tmp - value=$tail - fi - done <"$n" - set_value - eof + # + # "read" doesn't recognize lines that don't end with a newline. + # The cat-sed hack below works around this problems. + # + cat -E "$n" | sed 's/[^$]$/&\n/;s/$$//' | { + while read line; do + [ "$line" = "${line###}" ] || continue + tmp=`echo "$line" | awk '/^[^\t ]/ { print $1 }'` + tail=`echo "$line" | sed 's/^[^\t ]*[\t ]*//'` + if [ -z "$tmp" ]; then + [ -z "$tail" ] || value="$value $tail" + else + set_value + tag=$tmp + value=$tail + fi + done + set_value + eof + } done }