How to parse line by line from dmesg command?, i try using a while and read:

while read -r L; do
    echo "line: ${L}";
done < <(dmesg -c --level=err)

But can not echo the lines. I try using:

LINES=$(dmesg -c --level=err);
while read -r L; do
    echo "line: ${L}";
done <<< "$LINES"

But echo only a one line without content.

When call dmesg -c --level=err have a 5 lines with content.

How to parse this?


I guess that you forget that -c switch is to delete the content after the first invocation.

It's the simple reason why you don't have line echo-ed.

The first snippet is valid code.

Ensure your default shell is bash !

[[ $SHELL == *bash ]] && echo 'bash is the default shell' || echo >&2 "WTF"
  • Thank you very much, I was using that argument the wrong way. – F-Natic May 30 '20 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.