One line command line filter
tjreedy at udel.edu
Mon Sep 5 21:25:44 EDT 2011
On 9/5/2011 7:18 PM, Steven D'Aprano wrote:
> Terry Reedy wrote:
>> The doc says "-c<command>
>> Execute the Python code in command. command can be one or more
>> statements separated by newlines,"
>> However, I have no idea how to put newlines into a command-line string.
> I imagine that it depends on the shell you are using, but bash on Linux
> makes it simple: double quotes "..." are like Python's triple-quoted
> strings in that they can include newlines.
> [steve at sylar python]$ ls f*.py | python -c "import sys
>> print sys.stdin.read()"
I was guessing that whoever wrote the doc could do something like that.
As far as I know, there is no way to escape a newline with Windows
cmd.exe. (Someone please tell me if I am wrong!) An "unmatched" quote is
either ignored or matched by the newline!
C:\Programs\Python32> python -c "print('haha')
Terry Jan Reedy
More information about the Python-list