Or use a heredoc to not worry about competing quote chars:
# python << EOPYTHON
print("Congrats, ${USER}")
print("You are visitor ${RANDOM}")
print("This is {__name__}, running in ${pwd}")
print("It's a heredoc to allow both quote characters")
EOPYTHON
Re:Hypermodern Python
by moreaccountspls on Thursday May 28, 2020 @11:31AM
(#23338469)
Great trick with using the python standard lib! Thanks for posting that.
edit: You probably already know this, but for anyone reading along, piping `ls` is unsafe if you plan to use the paths for anything except for printing them out. A path on linux can contain any byte except for NULL, so when `ls` prints them out, you can get broken behavior if you try to break on newlines.
Another thing to consider is more of a middle-ground approach. Most systems do have a python interpreter, so you can use a lot of base python without worrying about dependency hell. I use inline python in bash all the time, e.g.
You can even use variable substitution, if you surround the python code in double quotes. Even mix f-strings and bash substitution