A twitter account @nixCraft posted one-liner to print your Linux distro version
. As in many other cases the suggestion is to use external processes like awk
. Because starting a new process is expensive, that makes the system to do unnesessary heavy lifting - and removes that “snappy” feeling from running your scripts.
Use an in-shell solution where possible, e.g:
function qrel {
# qrel (query release)is a quick function to get
# a value assosiated with a key in n /etc/os-release fie
# ${1} is the expected key
local IFS="="
key=$(tr "[:lower:]" "[:upper:]" <<<${1})
while read name value
do
value=${value#\"}
value=${value%\"}
[[ "${name}" == "${key}" ]] && {
echo ${value}
return
}
done </etc/os-release
}
Here are some examples:
$ qrel id
pop
$ qrel ID_LIKE
ubuntu debian
$ qrel version
20.10
$
But! What you you really should be doing is something like:
$ . /etc/os-release
$ echo $ID_LIKE
ubuntu debian
$
LOL
2021-05-11