From 54459160040738030b4f4875c108077436b667d9 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Wed, 28 Jun 2023 12:03:29 -0500 Subject: [PATCH] Add Run A cURL Command Without The Progress Meter as a Unix TIL --- README.md | 3 +- ...curl-command-without-the-progress-meter.md | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 unix/run-a-curl-command-without-the-progress-meter.md diff --git a/README.md b/README.md index 822ad18..df4c87a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1320 TILs and counting..._ +_1321 TILs and counting..._ --- @@ -1316,6 +1316,7 @@ _1320 TILs and counting..._ - [Repeat Yourself](unix/repeat-yourself.md) - [Replace Pattern Across Many Files In A Project](unix/replace-pattern-across-many-files-in-a-project.md) - [Run A Command Repeatedly Several Times](unix/run-a-command-repeatedly-several-times.md) +- [Run A cURL Command Without The Progress Meter](unix/run-a-curl-command-without-the-progress-meter.md) - [Safely Edit The Sudoers File With Vim](unix/safely-edit-the-sudoers-file-with-vim.md) - [Saying Yes](unix/saying-yes.md) - [Search Files Specific To A Language](unix/search-files-specific-to-a-language.md) diff --git a/unix/run-a-curl-command-without-the-progress-meter.md b/unix/run-a-curl-command-without-the-progress-meter.md new file mode 100644 index 0000000..3701eeb --- /dev/null +++ b/unix/run-a-curl-command-without-the-progress-meter.md @@ -0,0 +1,30 @@ +# Run A cURL Command Without The Progress Meter + +By default when you run a `curl` command that will output to the terminal, it +disables the progress meter for the request. When the response output is +redirected or piped somewhere else however, the progress meter will be +displayed in the terminal. + +```bash +$ curl -H "Content-Type: application/json" -G http://myurl.com | jq + % Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed +100 2515 0 2515 0 0 4184 0 --:--:-- --:--:-- --:--:-- 4184 +``` + +This can be disabled with the `-s` flag (which is short for `--silent`). + +```bash +$ curl -s -H "Content-Type: application/json" -G http://myurl.com | jq +``` + +However, the `-s` flag will also suppress error messages. This is a bit +unhelpful. You can then add in the `-S` flag (short for `--show-error`) to +ensure that error messages are shown even while the progress meter is +suppressed. + +```bash +$ curl -sS -H "Content-Type: application/json" -G http://myurl.com | jq +``` + +See `man curl` for more details.