The main disadvantage of using the here document is that the standard document input will be the here document. So if you have a script that wants to handle its standard input, python -c is almost the only option.
On the other hand, using python -c '...' concatenates single quotes for shell needs, so you can only use double quoted strings in your Python script; instead, using double quotes to protect the script from the shell creates additional problems (double-quoted strings undergo different substitutions, while single-quoted strings are literal in the shell).
Also, note that you probably want to also quote the here-doc separator, otherwise the Python script undergoes similar replacements.
python - <<'____HERE' print("""Look, we can have double quotes!""") print('And single quotes! And 'back ticks'!') print("$(and what looks to the shell like process substitutions and $variables!)") ____HERE
Alternatively, escaping works identically if you prefer this ( python - <<\____HERE )
source share