5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ズンドコキヨシ using git with bash {for / seq / /dev/null / expr / awk / 部分文字列取得 / if文}

Last updated at Posted at 2016-03-15

処理の流れ

  1. dmy.txtを作成
  2. git addでステージングに置く
  3. git commitでコミットメッセージ追加
  4. git log --onelineでコミットのハッシュ値を取得
  5. ハッシュ値のLSBが0,1かでzun,doko判定
  6. 以下略

code v0.1

zundoko-exec
#!/usr/bin/env bash


git init >& /dev/null

zuncount=0
totalcount=0
for idx in $(seq 1 100);
do
	echo $idx >> dmy.txt
	git add dmy.txt >& /dev/null
	git commit -m "zundoko" >& /dev/null

	totalcount=`expr $totalcount + 1`

	hash=`git log --oneline | head -n 1 | awk '{print $1}'`
	zeroOrOne=`echo $((${hash:6:1} % 2))` # check last character
	if [ $zeroOrOne == 0 ];then
		echo "doko"
		if [ $zuncount == 4 ]; then
			echo "KIYOSHI!"
			echo "total:$totalcount"
			break;
		fi
		zuncount=0
	else
		echo "zun"
		zuncount=`expr $zuncount + 1`
	fi
done

以下を使用している

  • for文
  • seq文
  • gitコマンド
  • /dev/null出力
  • awk
  • expr文
  • 部分文字列取得 ${hash:6:1}
  • if文

実行方法

動作確認
CentOS 6.5 (32bit)

gitログを書き換えてしまうため、gitログがないフォルダにて実行してください。

chmod +xで実行権限を付加して実行。

$ chmod+x zundoko-exec
$ ./zundoko-exec

またはchmodをしない場合は

$ bash zundoko-exec

結果

doko
doko
doko
zun
zun
zun
doko
zun
doko
zun
doko
doko
zun
doko
zun
doko
zun
zun
zun
zun
doko
KIYOSHI!
total:85
5
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?