Forums

bash: syntax error near unexpected token `('

I realize this topic has been covered numerous times online and I have implemented the solution of explict quotes around the string. But as I execute workon myvirtualenv it raises the subject error when the virtual environment is already active. Why does this occur?

(myvirtualenv) 21:33 ~/django_stackoverflow (main)$ echo 'secret_key=ley2+ra#(ec7bp2jt' > .env

(myvirtualenv) 21:33 ~/django_stackoverflow (main)$ echo 'set -a; source ~/django_stackoverflow/.env; set +a' >> ~/.virtualenvs/myvirtualenv/bin/postactivate

(myvirtualenv) 21:33 ~/django_stackoverflow (main)$ echo $secret_key
ley2+ra#(ec7bp2jt

(myvirtualenv) 21:34 ~/django_stackoverflow (main)$ workon myvirtualenv
bash: /home/binnybit/django_stackoverflow/.env: line 1: syntax error near unexpected token (' bash: /home/binnybit/django_stackoverflow/.env: line 1:secret_key=ley2+ra#(ec7bp2jt'

When you tried wrapping the secret key value is quotes were they double quotes (") or single quotes (') because they are different in bash. It should be single quotes eg secret_key='the_keys_value'