二つの時刻の間隔を計る簡易ストップウォッチ・スクリプトをBashで作ってみました。計測の単位は「sec」だけです。
【関連記事】
ーーーー
このポストの履歴
#!/bin/bash
# mySec: A Stopwatch script
#
# usage: mySec 0 ← Start-time in unit of sec.
# mySec ← Time-interval from Start-time in unit of sec.
# mySec now ← Current Time in unit of sec.
#
# example:
# $ mySec 0; sleep 3;mySec # Check#
# 3sec
# $ mySec 0 # Start the Stopwatch
# ... Somothing done ...
# $ mySec # Stop the Stopwatch
# 81sec
# $mySec now # Curent Time in unit of sec.
# 1339041714
#
# 2012-06-06 (水) 20:07, by mNeji
#set -x
if [ "$1" = "now" ]
then
# for "mySec now" ------------------------------------------------
echo `date +%s`
exit 0
fi
if [ -z $1 ]
then
# for "mySec" -----------------------------------------------------
Stop=`date +%s`
Start=`cat ${0}.start`
time_interval=`expr ${Stop} - ${Start} `
echo "${time_interval}sec"
rm -f ${0}.start
else
# for "mySec 0" --------------------------------------------------
# echo `date +%s` | tee ${0}.start
date +%s > ${0}.start
fi
【関連記事】
ーーーー
このポストの履歴
- 開始: 2012-06-06-20:30(JST)
- 修正: 2012-06-07 (木) 13:06
0 件のコメント:
コメントを投稿