有没有一种方法可以用两个参数解析一个参数?
这是我的示例脚本。
#!/bin/bash
while getopts "p:t:" param; do
case $param in
p) ping -c3 $OPTARG
;;
t) traceroute -4 $OPTARG
;;
esac
done
如果我使用参数-p或-t运行脚本,则一切正常。
:~# ./test.sh -p 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=52 time=30.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=52 time=29.9 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=52 time=29.9 ms
:~# ./test.sh -t 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1 bbrouter (192.168.1.1) 1.302 ms 0.976 ms 0.769 ms
2 100.68.0.1 (100.68.0.1) 14.142 ms 14.113 ms 15.740 ms
What i'm trying to aim is would it be possible to use a parameter -pt and just using one argument to be parsed.
Something like this. :~# ./test.sh -pt 8.8.8.8