2
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 1 year has passed since last update.

`curl`の実行時に、存在しないURLを指定してもリターンコードは0になる、自動処理では扱いづらいことがあるので、 `curl -f`のように`-f`オプション指定するとエラーコードが返ってくるようになった。という備忘録

Last updated at Posted at 2022-07-29

curlの実行時に、存在しないURLを実行してもリターンコードは0になる

$ curl -f https://example.com/testtesttest
$ echo $?
0

自動処理では扱いづらいことがあるので、
curl -fのように-fオプション指定するとエラーコードが返ってくるようになった

$ curl -f https://example.com/testtesttest
curl: (22) The requested URL returned error: 404 Not Found
$ echo $?
22

これで自動処理でもリターンコードをみて判断ができる

参考

2
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
2
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?