Closed fritzrehde closed 2 years ago
I found the issue: gdrive
prints to stderr instead of stdout. So this is what works for now:
stdbuf -oL gdrive upload "$FILE" 2>&1 \
| stdbuf -i0 -oL tr '\r' '\n' \
| grep --line-buffered '[^[:blank:]]' \
| while read LINE; do
echo "do something with: $LINE"
done;
But this is still quite complicated, so I'll file another issue for better logging output.
I want to parse the output of the upload command line by line with a while loop in a shell script. However,
gdrive
doesn't print new updates (e.g. updated progress percentage) to new lines on stdout, I think it uses\r
to remove the last line so it looks like there is only one output line that is constantly getting updated. I am trying to convert all\r
s into\n
s with this script, but it isn't working. It keeps printing the gdrive output instead of the inside of the while loop.Any ideas how to fix this script (or is this a bug in
gdrive
)?