Skip to main content
added 15 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Your data has a carriage return at the end:

$ status=$'409\r'
$ echo "<<$status>>"
>>409

To remove it, use tr -d '\r'tonumber in jq:

status=$( curl ... | jq ... | tr -dr '\r''.[0].status|tonumber' )

Also note that there is no need for status to be an array variable, as in your script, as far as I can see.

Your data has a carriage return at the end:

$ status=$'409\r'
$ echo "<<$status>>"
>>409

To remove it, use tr -d '\r':

status=$( curl ... | jq ... | tr -d '\r' )

Also note that there is no need for status to be an array variable, as in your script, as far as I can see.

Your data has a carriage return at the end:

$ status=$'409\r'
$ echo "<<$status>>"
>>409

To remove it, use tonumber in jq:

status=$( curl ... | jq -r '.[0].status|tonumber' )

Also note that there is no need for status to be an array variable, as in your script, as far as I can see.

Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Your data has a carriage return at the end:

$ status=$'409\r'
$ echo "<<$status>>"
>>409

To remove it, use tr -d '\r':

status=$( curl ... | jq ... | tr -d '\r' )

Also note that there is no need for status to be an array variable, as in your script, as far as I can see.