Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My script takes a key as its third argument, and it can have any kind of input...including characters that bash complains about.

I'd really like to use this one-off script right from the terminal, can someone explain how I could get my input to work if it looks like this?

>/my/scripts $ python script.py string 123 spe[i@lk;y
/bin/sh: Syntax error: "(" unexpected
y: command not found
>/my/scripts $ python script.py string 123 "spe[i@lk;y"
/bin/sh: Syntax error: "(" unexpected

And yes, I do have the #! usr/bin/env python shebang in my script.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The script can do nothing to tell bash not to apply its usual globbing and interpolation rules. In fact, there is no way to prevent it, although you can disable some aspects (specifically globbing and variable interpolation but not the special meaning of, say, parentheses). You need to use some form of quoting.

That said, the parenthesis error tells me that it's reading your Python as a shell script, which means you probably have the shebang line in the wrong place. It must be the first line of the script (no blank lines before it), it may not start with leading spaces, and if your example is what you actually used then you are missing a leading slash on /usr/bin/env.

share|improve this answer
    
You were right -- I had my shebang messed up...but it's still rejecting my input based on @ and the like...I'll just take the extra step and run it straight from the chevron. Thanks anyway. –  Droogans Apr 6 '12 at 3:25

Your Answer

 
discard

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.