My pet peeve, grep unnecessarily followed by awk/sed.
Original: df -h | grep "$partition" | awk '{print $5}' | sed 's/%//'
Efficient: df -h | grep -Po "\d+(?=%\s+$partition)"
Original: df -h | grep "$partition" | awk '{print $5}' | sed 's/%//'
Efficient: df -h | grep -Po "\d+(?=%\s+$partition)"
# df -h | grep "$partition" | awk '{print $5}' | sed 's/%//'
24
# df -h | grep -Po "\d+(?=%\s+$partition)"
#I think the first one is much easier to read.
df -h | grep -Po "\d+(?=%\s+\Q$partition\E)"https://stackoverflow.com/questions/54405892/are-q-and-e-sup...
Thanks!
At some point I should probably write an article about the 20k lines of bash and a little python that power my homelab and various automations. Bash isn't perfect but often 99% good enough is fine.