2

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?

e-info128
  • 175

1 Answers1

1

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"