0
curl -SX POST http://127.0.0.1/open/api/pudao/fileupload
: $(curl -SX POST http://127.0.0.1/open/api/pudao/fileupload)

(The command substitution is not useful here as such, it's just a minimal reproducible example.)

In the latter case, I see a progress indicator like

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to 127.0.0.1 port 80 after 8 ms: Connection refused

enter image description here

Why does the same command produce different output?

tripleee
  • 175,061
  • 34
  • 275
  • 318
一无所有
  • 101
  • 8
  • Does this answer your question? [Difference between ${} and $() in Bash](https://stackoverflow.com/questions/27472540/difference-between-and-in-bash) – sinclair Feb 01 '23 at 13:35
  • The actual answer to the question is probably that `curl` behaves slightly differently when its output is not to a terminal. But we are at loss as to why you would expect to run the empty output as a command. – tripleee Feb 01 '23 at 13:59
  • I can concur that this behavior is unexpected and probably a bug. As such, we have a number of questions about why some utilities like `git` and `top` behave differently when used interactively; I'm tempted to vote to close as a duplicate of one of those. – tripleee Feb 02 '23 at 05:28

1 Answers1

0

isatty is used in the curl source code; the isatty() function returns 0 in a command subtitution $(). It will happen again when you redirect stdout to elsewhere without a tty. I think is the real reason.

tripleee
  • 175,061
  • 34
  • 275
  • 318
一无所有
  • 101
  • 8