Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to curl | grep some data from a webpage but after setting language to English. In a browser, I can do this by clicking on a link.

I first get the SelectCulture page and save the cookie in a file, then I use it to get the page I need:



curl -s \
    --location \
    --cookie "$tmp_file" \
    --cookie-jar "$tmp_file" \
    --user-agent Mozilla/4.0 \
    --data-urlencode "ReturnUrl=http://it.bca-europe.com/Default.aspx" \
    "http://it.bca-europe.com/Home/SelectCulture/en-GB-BDIT" | egrep "Ospite|Guest"

curl -s \
    --location \
    --cookie "$tmp_file" \
    --user-agent Mozilla/4.0 \
    "http://it.bca-europe.com/Default.aspx" | egrep "Ospite|Guest"

The problem is that on first run, when the cookies file does not exist yet, somehow the language doesn't change (you get italian Ospite instead of Guest), whereas the script works from the second run.

This, for example, avoids the need to use a temporary file instead of a static file. Moreover, weirdly, I can't get it to work in a single run.

Any advice?

share|improve this question
Why would the first curl call need the --cookie and the --cookie-jar? From what I gather, the first call should fill the jar but it should not need (an empty?) cookie at all. I think this could be the culprit, i.e. why it works the second time (since the jar is non-emtpy)...maybe. – sr_ Mar 14 '12 at 9:44
@sr_: you are right, it's overkill, it's the result of some trials – neurino Mar 14 '12 at 15:29
up vote 2 down vote accepted

A browser usually sends a list of accepted languages with every request. CMSes often use this when no cookie is set. (In theory, the cookie is just a fallback and the language settings are correct.) This results in <span>Hello Guest</span> for me:

curl -s  --location -H 'Accept-Language: en' "http://it.bca-europe.com/Home/SelectCulture/en-GB-BDIT" | egrep "Ospite|Guest"
share|improve this answer
and this is right what I was looking for, thank you. – neurino Mar 14 '12 at 15:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.