'CentOs 7 - how run this command (including quotes/options) using watch? (watch -n2 "command")
I need run the command
awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime
each 2 or 3 seconds, I try multiple options:
watch -n2 "'{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime"
watch -n2 "'{print int($1/3600)":"int(($1%3600)/60)":"int(\$1%60)}' /proc/uptime"
watch -n2 "'{print int(\$1/3600)":"int((\$1%3600)/60)":"int(\$1%60)}' /proc/uptime"
watch -n2 "'{print int(\$1/3600)":"int(\$1%3600/60)":"int(\$1%60)}' /proc/uptime"
watch -n2 "awk '{print int(\$1/3600)":"int(\$1%3600/60)":"int(\$1%60)}' /proc/uptime"
watch -n2 "awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime"
watch -n2 "awk '{print int(\$1/3600)":"int((\$1%3600)/60)":"int(\$1%60)}' /proc/uptime"
and more...
but never work for me
thanks
Solution 1:[1]
You have to escape " inside " too.
watch "awk '{print int(\$1/3600)\":\"int(\$1%3600/60)\":\"int(\$1%60)}' /proc/uptime"
but really, just
watch -x awk '{print int($1/3600)":"int($1%3600/60)":"int($1%60)}' /proc/uptime
When in doubt, use printf "%q" to quote stuff. I wonder if the following is fine:
watch "$(printf "%q " awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime)"
But in interactive shell, I would just make a function, it's the simplest:
f() { awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime; }
export -f f
watch bash -c f
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KamilCuk |
