Skip to content
Advertisement

How do I pass “>>” or “<<" to my script without the terminal trying to interpret it as me either appending to something or getting stdin?

My python script can take a series of bitwise operators as one of its arguments. They all work fine except for “=<<” which is roll left, and “=>>” which is roll right. I run my script like ./script.py -b +4,-4,=>>10,=<<1, where anything after -b can be any combination of similar operations. As soon as the terminal sees “<<” though, it just drops the cursor to a new line after the command and asks for more input instead of running the script. When it sees “>>”, my script doesn’t process the arguments correctly. I know it’s because bash uses these characters for a specific purpose, but I’d like to get around it while still using “=>>” and “=<<” in my arguments for my script. Is there any way to do it without enclosing the argument in quotation marks?

Thank you for your help.

Advertisement

Answer

You should enclose the parameters that contain special symbols into single quotation marks (here, echo represents your script):

> echo '+4,-4,=>>10,=<<1'
+4,-4,=>>10,=<<1

Alternatively, save the parameters to a file (say, params.txt) and read them from the file onto the command line using the backticks:

> echo `cat params.txt`
+4,-4,=>>10,=<<1

Lastly, you can escape some offending symbols:

> echo +4,-4,=>>10,=<<1
+4,-4,=>>10,=<<1
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement