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?

1

1 Answer 1

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"
1
  • Thank you very much, I was using that argument the wrong way.
    – e-info128
    Commented May 30, 2020 at 2:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .