LoginSignup
1
4

More than 5 years have passed since last update.

シェルスクリプトで1月17日が火曜日だった年を調べる

Last updated at Posted at 2017-01-18

1995年から今年まで1月17日が火曜日だったかどうか調べるBash用oneliner。grepの出力は捨てて返り値だけ使うのが味噌。

for i in {1995..2017}; do if ncal 1 $i | grep '^火.*17' >/dev/null; then echo "$i"年1月17日は火曜日だった。; else :; fi; done

ifの条件式に返り値を使っているのだと明示すると、

for i in {1995..2017}; do ncal 1 $i | grep '^火.*17' > /dev/null; if [ $? -eq 0 ]; then echo "$i"年1月17日は火曜日だった。; else :; fi; done

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4