also, when running the tests i first noticed that because in yours debian came first of course some additional syscalls would be in place to test for the first grep, therefore i did `for i in fedora debian...` etc to make it fair
@tost oh, maybe u could shed me light into a question i have.. why fedora and debian syscall's total numbers are so different even for the same script?
@tost i have to confess, while your solution is 19 chars less.. mine is 84 syscalls more efficient.. :acat_hearteyes: (only in fedora, in debian is only 1 syscall more efficient): https://pastebin.com/kn4tLtEX
@tost so, first: u’re amazing, can you believe i never thought before of doing it like this?
the var is set after the loop finishes, so you can reuse it later!
i was approaching it something like (1), where my thought process was: first i query the data, then i switch/case, decide what to do after
but your approach (2) goes like the following: you make up a list of your own and run queries, if the query fails more things are queried, but if it goes okay you exit it and save it, you’re using the query as a control flow thing, and because the last success value will be stored in the var loop, you can parse with switch/case later! finally, there’s an extra element in the loop list to not always end with one of the true options!
your (2) is very smart and creative! yes the thought process of it may not be as straightforward as “just query data then parse it”, and you’re using the querying line as something to control the loop but it’s amazing! ???
it made me realise i barely ever use break statements smol brain :02think:
thx a lot u’re great :02_cheer:
(1):
check_distro() {
distro=$(
grep -Po "(?<=^ID_LIKE=).+" /etc/os-release ||
grep -Po "(?<=^ID=).+" /etc/os-release
)
case "$distro" in
"debian"*)
: # do debian-based thing
;;
"fedora"*)
: # do fedora-based thing
;;
*)
: # err distro not supported
;;
esac
}
(2):
check_distro2() {
for distro in debian fedora error
do
grep -qe $distro /etc/os-release && break
done
case "$distro" in
"debian"*)
: # do debian-based thing
;;
"fedora"*)
: # do fedora-based thing
;;
*)
: # err distro not supported
;;
esac
}