0
1

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.

シェルスクリプトを書く際にifを事前チェックするためのfunction

0
Posted at

ほしいもの

shellscriptを書く際のif文をチェックしたい。

対応

以下のコードをzshrcに入れた。

function bool {
  eval "
  if [[ $@ ]] ; then
    echo 'true'
  else
    echo 'false'
  fi
  "
}

以下みたいに使う。

$ bool -f .zshrc
true
$ bool ! -f .zshrc
false

気持ち

ちょっと作業を自動化したいときにシェルスクリプト書くじゃないですか。
↓みたいなやつ。

if [[ `date` =~ 水曜日 ]]; then
  echo '今日は水曜日なので可燃ごみ';
fi

このifの中身の書式にいつも戸惑ってる上に、いちいちシェルスクリプト実行してチェックしてるのでとても生産性が低かった。

なんか既存のものがあったら悲しいですが教えてください。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?