計算一組命令所花費時間。
#cat time_take.sh
#! /bin/bash #time_take.sh start=$(date +%s) for ip in 192.168.2.{1..50} do ping $ip -c 2 &> /dev/null if [ $? -eq 0 ] then echo $ip is alive. else echo $ip is not alive. fi done end=$(date +%s) difference=$(( end - start )) echo Time taken to execute commands is $difference seconds.
參考:linux shell腳本攻略