タグ

ブックマーク / ykot.hateblo.jp (1)

  • shellで日付比較 - void*

    shellばかりいじっているから、最近、shellネタばかりです。shell上での日付比較は、秒に置き換えてやると、手っ取り早いです。 # 0 : 同一日時 # 1 : $1 の方が新しい日付 # 2 : $2 の方が新しい日付 function datecheck() { dt1=`date -d "$1" '+%s'` dt2=`date -d "$2" '+%s'` if [ $dt1 -eq $dt2 ]; then return 0 elif [ $dt1 -gt $dt2 ]; then return 1 elif [ $dt1 -lt $dt2 ]; then return 2 fi }結構、便利に使えます。

    shellで日付比較 - void*
  • 1