Last active
July 9, 2016 02:46
-
-
Save tomoyamkung/d17053e8bf57258e0a00bab064db8926 to your computer and use it in GitHub Desktop.
コマンドがインストールされているかを確認するスクリプト。 `which` を使って指定されたコマンドがシステムに存在するかを確認するスクリプトと、そのユニットテストを作成。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function installed_command() { | |
which $1 > /dev/null 2>&1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# dotfiles/etc/test 直下に移動する | |
cd `dirname $0` | |
# テスト対象のスクリプトを読み込む | |
source ../lib/installed_command.sh | |
# `ls` コマンドは存在するので `$? = 0` になるはず | |
installed_command ls | |
if [ ! $? -eq 0 ]; then | |
echo "ls コマンドは存在します" | |
fi | |
# `dummy_command` コマンドは存在しないので `$? != 0` になるはず | |
installed_command dummy_command | |
if [ $? -eq 0 ]; then | |
echo "dummy_command コマンドは存在しません" | |
fi | |
# 別解 | |
installed_command ls || echo "ls はインストールされているはずです" | |
installed_command dummy_command && echo "dummy_command はインストールされていないはずです" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment