One line command line filter

Steven D'Aprano steve+comp.lang.python at
Tue Sep 6 01:18:37 CEST 2011

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"

Other shells may be different.


More information about the Python-list mailing list