0
0

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.

失敗するかもしれないシェルコマンドを無視する

Posted at

凄く簡単なものなのですが、あるパイプラインで、Create Role Assignment をするコマンドがあり、既に既存で存在するという可能性があるので、最初の一回のみ実行したいというシーンがありました。ほっといたらエラーで終わって何もしないのでよいのですが、exitステータスのため、Pipeline自体がFailします。

このようなケースの場合にどうすればよいでしょう?

凄く単純で

fail.sh
# !/bin/bash
exit 1

と必ず失敗するファイルを作成します。

$ chmod +x ./fail.sh
$ ./fail.sh
$ echo $?
1
$ ./fail.sh | true
$ echo $?
0

うん。簡単。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?