Problem

You want to embed Python code inside a Bash script.

Solution

Here is a possible solution:

#!/usr/bin/bash # name.sh # Example: # Write a bash script that has one parameter: your name. # It prints every second character of your name. TFILE="`basename $0`.$$.py" cat <<END >$TFILE #!/usr/bin/env python import re import sys bash_name = re.sub(r'\.\d+\.py', '', sys.argv[0]) def process(s): print s[::2] def main(): if len(sys.argv) > 1: process(sys.argv[1]) else: print "Usage: {0} <parameter>".format(bash_name) if __name__ == "__main__": main() END chmod u+x $TFILE ./$TFILE "$@" /bin/rm $TFILE

Usage:

./name.sh Your_Name Yu_ae # output