0

I've begun working with Bash and have picked up on redirection of stdout and stderr, but as I have started working with Curl and Wget I notice that both of these programs send not only their errors to stderr but also their output from stdout. My script downloads a file with curl and redirects any errors to a file, then the script checks if the error file exists and if it does the script terminates after returning the error message. I am choosing to redirect the stderr to a file first so I can achieve some formatting on the error as I do not want to fill the end users entire screen with the contents of the curl or wget status if it fails. The issue is this file is created regardless of if the download succeeds or not. I really am curious as to why both stderr and stdout are sent to the same place and if this occurs with any other programs I should be aware of.

The curl command:

curl https://rclone.org/install.sh 2> /tmp/install_errors

  • How are you determining that curl "redirects stdout to stderr"? Make sure you're providing a [mre] -- steps others can follow to see the problem themselves, ideally _without_ making changes to their computer. – Charles Duffy Jan 18 '23 at 20:10
  • 1
    And yes, it's completely normal for `2>destination` to always, unconditionally create a file: the redirection is run before `curl` is started at all, because the file has to exist before the shell can hook curl's stderr up to it. – Charles Duffy Jan 18 '23 at 20:11
  • 1
    (Also, you shouldn't read stderr to determine if an error occurred; stderr contains not just error messages but also all "diagnostic" content, which is a very broad description; logs, prompts, and much else are all diagnostic in nature, because they tell the operator what's going on with the program while it runs; the only thing that's _not_ diagnostic in nature but is instead "normal output" for curl is the actual text of the file being downloaded) – Charles Duffy Jan 18 '23 at 20:12

0 Answers0