embedding short python scripts inside a bash script -
I want to embed the text of a small dragon script inside a Bash script, say, my .bash_profile
. What is the best way to go about doing this?
The solution is to call the Python interpreter with the option of -c
, and interpreter to exec
whatever stdin
. From there, I can create simple tools like the following, allow me to process the text for use in my interactive prompt:
function pyexec () {echo "$ ( / Usr / bin / python - C 'import sys; exec sys.stdin.read ()') "} function traildirs () {pyexec & lt; End trail = int ('$ {1: -3}') import os home = os.path. Cwd = cwd.replace (home, '~', 1) joined in parts = cwd.split ('' 'home' '' '= os.path.join (* parts [-trail:]) if Lane (Parts) & lt; = Trail and are not included. Startswith ('~'): Included = '/' + joined to the printed print END} This approach looks a little strange to me, and I'm wondering what can be the options to do this in this way. . My bass scripting skills are very low, so I am particularly interested in hearing if I am doing some stupid things from the BASH Interpreter's perspective.
Python interpreter -
to stdin
Accepts the command line as a synonym so that you can replace the call
P>
Comments
Post a Comment