On 10/24/19 10:27 AM, Omar Sandoval wrote:
On Mon, Oct 21, 2019 at 03:57:18PM -0700, Bart Van Assche wrote:
+# System uptime in seconds.
+_uptime_s() {
+ local a b
+
+ echo "$(</proc/uptime)" | {
What's wrong with cat /proc/uptime? Or even better,
{ read ... } < /proc/uptime
Hi Omar,
As you probably know 'cat' triggers a fork() system call but echo
$(<...) not. This is a performance optimization. Input redirection would
also work.
+ read -r a b && echo "$b" >/dev/null && echo "${a%%.*}";
What's the point of the echo "$b" here?
That echo "$b" statement suppresses a shellcheck warning about $b not
being used.
Seems like this could all be condensed to:
{ read -r s && echo "${s%%.*}" } < /proc/uptime
But that's more cryptic than it needs to be. Can we just do:
awk '{ print int($1) }' /proc/uptime
That's a valid alternative, but an alternative that triggers a fork()
system call. I don't have a strong opinion about which alternative to
choose. Do you perhaps have a preference?
Thanks,
Bart.