In Linux I use a script to ping a couple of addresses. Now I want that the user can do: bash Script 50-60
And that the script pings the addresses 192.168.100.50 - 192.168.100.60 I use xx-yy to do this and I tried but the part after the shift
is wrong.
for i in $*;
do
case $* in
"XX-YY" ) shift;
ping -c 1 192.168.0.$1 - $i
done
Script:
#!/bin/bash
start=${1%-*}
end=${1#*-}
for ((i=start;i<=end;i++));do
ping -c 1 192.168.0.$i
done
Usage:
bash path_to_the_Script 50-60
A little explanation:
I used bash parameter expansion to extract start
and end
from the input string 50-60
.
${1#*-}
is the string after the first match of a -
in $1
and
${1%-*}
is the string before the last match (first match from right) of a -
in $1
您可以尝试以下逻辑:ping 192.168.100。{50..60}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.