re-implement header/data splitting in ed(1)

somehow the original way (stdout/stderr) didn't work in dash
(which is /bin/sh in Debian, and rather limited, that is, a good
testing ground for POSIX shell compatibility)
This commit is contained in:
Matthias Rampke
2012-06-26 21:20:28 +02:00
parent 14b6847205
commit 94e310791d

View File

@@ -47,24 +47,25 @@ temp2=$(mktemp "$1.XXXX")
url="${api}screen_name=${1}&count=200&page=${page}${since}&include_rts=true&trim_user=1&include_entities=1" url="${api}screen_name=${1}&count=200&page=${page}${since}&include_rts=true&trim_user=1&include_entities=1"
echo "curl -s \"$url\"" echo "curl -s \"$url\""
curl -si "$url" > $temp curl -si "$url" | tee $temp2 > $temp
echo $? echo $?
{ # keep only headers in $temp2
{ while read -r ed -s $temp2 << "EOF_ED1"
do /^[[:space:]]*$/
if test "$REPLY" = $'\r' .,$d
then wq
break EOF_ED1
else
echo "$REPLY" >&2 # print header to stderr
fi
done
cat; } < $temp > $temp2
} 2>&1 | # redirect back to stdout for grep
grep -iE 'rate|status' # show the interesting twitter rate limits
mv $temp2 $temp # keep only content in $temp
ed -s $temp << "EOF_ED2"
/^[[:space:]]*$/
1,.d
wq
EOF_ED2
grep -iE 'rate|status' $temp2 # show the interesting twitter rate limits
if test "$(xmlstarlet sel -t -v "count(//statuses/status)" $temp 2>/dev/null)" -eq 0 if test "$(xmlstarlet sel -t -v "count(//statuses/status)" $temp 2>/dev/null)" -eq 0
then then