Bash escaping and syntax -
i have little bash file intend utilize determine current ping vs average ping.
#!/bin/bash output=($(ping -qc 1 google.com | tail -n 1)) echo "`cut -d/ -f1 <<< "${output[3]}"`-20" | bc
this outputs ping - 20 ms, number want. however, want prepend +
if number positive , append "ms".
this brings me overarching problem: bash syntax regarding escaping , such heavy "indenting" kind of flaky.
while i'll satisfied reply of how wanted, i'd link to, or explanation of how bash syntax works dealing sort of thing.
output=($(ping -qc 1 google.com | tail -n 1)) echo "${output[3]}" | awk -f/ '{printf "%+fms\n", $1-20}'
the +
modifier in printf
tells print sign, whether it's positive or negative.
and since we're using awk
, there's no need utilize cut
or bc
field or arithmetic.
bash
No comments:
Post a Comment