A simple bash script that can set a cookie when executed via web :

echo "Set-Cookie: eee=1"
echo "Content-type: text/html"
echo ""
echo "test"

I replaced the entire codes above with the following:

#!/usr/bin/env python
import os

print 'Set-Cookie: eee=1'
print 'Content-Type: text\n'

print '<html><body>'

a = os.environ.get('HTTP_COOKIE')
print a

print '</body></html>'

this one can now both set and retrieve a cookie.

but it is no longer a bash script. it is a python script.

the question is.. how to retrieve the cookie via bash script itself.. ?

  • Do read unix.stackexchange.com/questions/131766/… — especially if you're going to process data from a remote client. In a shell script, echo $VARIABLE does not print the value of the variable, it does further processing. – Gilles Sep 2 '14 at 22:16

This is your second script in bash:


echo "Set-Cookie: eee=1"
echo "Content-Type: text"

echo "<html><body>"

printf '%s\n' "$HTTP_COOKIE"

echo "</body></html>"

os.environ.get('HTTP_COOKIE') gets the evironment variable called HTTP_COOKIE, within bash you can easly call the variable with "$HTTP_COOKIE".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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