Q:

How to give arguments after Here Document?

I want to execute a python script via “Here Document” following some arguments in my bash shell script, as follows
python <<'__SCRIPT__'
...
__SCRIPT__
ARG1 ARG2 ...

But don't know how to give these arguments. I have tried putting them following python, following SCRIPT and a new line right after SCRIPT. But errors are reported in all of the cases when executed.
So what is the right way?
BR, RUOCHEN

A:

The arguments are part of the command.
python - arg1 arg2 << ...

A:

<<__SCRIPT__ is not actually a script passed to python, it's a stream containing the script. You have to tell python where to get the script, which is - in this case. That's why python - arg1 arg2 <<'__SCRIPT__':
$ cat here-py.sh
python - foo bar <<__SCRIPT__
import sys
print(sys.argv)
__SCRIPT__
$ ./here-py.sh
['-', 'foo', 'bar']

