bashvariablesunixcurlbase64

How to catch cURL (piped through base64) download failure


I am using cURL to download files and store them in variables (via base64):

output=$(curl -L -o - $url | base64)

The problem is that I don't know how to check if the download was successful (if so, the file should be saved in a variable).


Solution

  • Try

    if output=$(set -o pipefail; curl ... | base64); then
      # handle success
    else
      # handle failure
    fi