Both are setting a variable kernelHash
based on the value of the file whose name/path is stored in the variable $SecureBootJson
. I will assume you understand what the pipes |
are doing.
Grep
man grep
helps us parse the arguments to grep:
-m 1
: Stop reading a file after 1 matching line
-o
: Print only the matched (non-empty) parts of a matching line
-P
: Interpret the regex as a Perl regex
Grep regexes
'"uImage-[0123456789.]*-ts-armv7l": [^, }]*'
Matches a "key": value
pair
"uImage-
: literally
[0123456789.]*
: zero or more digits or dots
-ts-armv7l":
: literally
[^, }]*
: zero or more characters that are not ,
,
or }
and
'"uImage-[0123456789.]*-ts-armv7l.*?\btype\b"'
Matches a "quoted" string
"uImage-
: literally
[0123456789.]*
: zero or more digits or dots
-ts-armv7l
: literally
.*?
: lazily matches zero or more non-newline characters
\btype\b"
: Matches the word 'type' using word boundaries
cut
cut -f3 -d ' '
From man cut
:
-f3
: return the 3rd field
-d ' '
: split on single spaces
So this cut command splits the string on spaces and returns the 3rd section.
The sed commands
sed 's/^.*: //'
Replaces all non-newline characters between the beginning of the line the rightmost ': ' with nothing. Assuming the grep
left us with a "key": value
line where value
does not contain ': '(which it cannot thanks to grep), we are left with value
.
sed 's/,//'
Replaces the first ,
found in the string with nothing.
Note
There are a number of quirks and opportunities for improvement in these commands, but I have not included them in the main body of the answer, because the question was "what does this do?". My foremost suggestion would be the use of jq
to parse Json.