1

I am trying to write a shellscript that will assign a variable to curl output. The output of this curl command when I run it from the command line is this:

$curl "test.test.com/landing/505978290?c=Area%20Rug"
www.test.com/test/test?test=test

Going to this url is supposed to simply output a text document with another url. I want to test that this second url is the url it is supposed to be.

   url = $(curl "test.test.com/landing/505978290?c=Area%20Rug")
   if [$url -gt "www.tazinga.com/landing/505978290?c=area%20rug&si=gw&alt_css=silver&sv=34&"]         echo ""test.test.com/landing/505978290?c=Area%20Rug did not redirect properly"
    else
        echo "Right URL"
    fi

However, when I run the shellscript I get this output:

       % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    75    0    75    0     0    997      0 --:--:-- --:--:-- --:--:--  1013
Command not found. 
-bash: [: missing `]'
yes

If I try to print out url, I get an empty string. I get this regardless as to whether or not the string correctly matches or not. Why is curl operating differently in a shellscript than from the command line.

1 Answer 1

6

There should no have spaces when assign url, try this :-

url=$(curl -s ...)

note : curl -s is to suppress the progress meter

Sign up to request clarification or add additional context in comments.

2 Comments

That helps. Now I need to the variable url to be a string. When I try to run this command I get this error now: No such file or directory
gt is meant for integer expression, and you try to compare the exact string to string?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.