My little script extracts DOI's from a csv files in order to check whether they are right. The number should equal 3, and if it doesn't, I want to output an message.#!/bin/bashdoi=j.1540-6261.2011.01681.xnum_redirect=[[ curl -L -s -w %{num_redirects} http://dx.doi.org/$doi -o /dev/null ]]echo $num_redirectif (( $num_redirect -eq 3 ))then  echo $doi  is correctelse  echo $doi  is wrongfiAlthough num_redirects appears to be 3 in my terminal, I keep getting the error ((: -lt 3 : syntax error in expression (error token is 3 ) and also a wrong output.Then I checked whether num_redirect is actually an integer withcase $num_redirect in   ''|*[!0-9]*) echo bad ;;   *) echo good ;;esac(https://stackoverflow.com/a/3951175/3621464) and I receive bad.Now I wonder what kind of output curl -s -w %{num_redirects} is. echo ${#num_redirect} says it's of 0 length.
Nnumber of HTML redirects from cURL
bash;shell script;curl
The curl command is executed but its output is not assigned to num_redirect. This means that the output of curl is shown, i.e. 3 (without a newline). However, a newline is inserted when echo $num_redirect is run, as the variable is empty. This gives you the impression that the variable num_redirect has the value of 3.You should either use backticks or $() to execute a command and capture its output on stdout.num_redirect=$(curl -L -s -w %{num_redirects} http://dx.doi.org/$doi -o /dev/null)Also, you should compare the variable to an integer by using [ and ]. Now you are, again, just evaluating the command.if [ $num_redirect -eq 3 ]then    ...else    ...fi