私は結果をチームシティー(継続的な統合テスト)に報告するコマンドをカプセル化するbash関数を持っています。私の問題は、!
を先読みして結果を無効にできないことです。を使用! bash関数への引数で
function run_as_teamcity_test
{
local name="$1"
shift
echo "##teamcity[testStarted name='$name' captureStandardOutput='true']"
if ! [email protected]; then
ANY_TEST_FAILURE=true
FAILED_TESTS="${FAILED_TESTS} ${name}\n"
echo "##teamcity[testFailed name='$name']"
echo -e "\033[31mTests failed: $name\033[0m"
fi
echo "##teamcity[testFinished name='$name']"
}
これは動作します:
> run_as_teamcity_test "Should be true" echo "OK"
##teamcity[testStarted name='Should be true' captureStandardOutput='true']
OK
##teamcity[testFinished name='Should be true']
これは動作しません:
> run_as_teamcity_test "Should be false" ! echo "Not OK"
##teamcity[testStarted name='Should be false' captureStandardOutput='true']
!: command not found
##teamcity[testFailed name='Should be false']
Tests failed: Should be false
##teamcity[testFinished name='Should be false']
バッシュは、コマンド!
探し代わりの組み込みを使用しています。その代わりに組み込み関数を使用する方法はありますか?
[Bashのよくある質問050](http://mywiki.wooledge.org/をBashFAQ/050)が適用されます。 '!'は構文であり、コマンドや引数ではないので、単純に '$ @'の展開の一部として埋め込むことはできません。 – chepner
'' Ok''や '' Not Ok''の単純な文字列チェックをしてみませんか? – Inian
コマンド 'echo" OK "は追加の引数で別のスクリプトを実行するためのプレースホルダです。 – morotspaj