The issue is that in your Bash function, the python <<EOF ... EOF heredoc does not pass the command-line arguments (42) to the Python script. The sys.argv list in Python only contains the script name (or an empty string if run interactively) because no arguments are being passed.
To make sys.argv contain ['', '42'] (or similar), you need to explicitly pass the arguments to the Python command. Here’s how you can fix it:
Use the -c flag to pass the script as a string and include the arguments:
bashmy_test() { python -c " import sys print(f'{sys.argv=}') " "$@" } my_test 42
"$@" expands to all positional parameters as separate words, so 42 is passed as an argument to the Python script.-c flag allows you to pass the script directly as a string.pythonsys.argv=['-c', '42']
If you want sys.argv to start with an empty string (as in your example), you can adjust the script like this:
bashmy_test() { python -c " import sys sys.argv = [''] + sys.argv[1:] print(f'{sys.argv=}') " "$@" } my_test 42
pythonsys.argv=['', '42']
Vibe can make mistakes. Check answers. Learn more