Created
May 14, 2019 22:53
-
-
Save jpralves/0bbc8edc9582fbfb97e0e51c195a9622 to your computer and use it in GitHub Desktop.
Sample bash script with embedded python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
python_code_in_bash() { | |
python3 <(cat <<EOF | |
import sys | |
lines = sys.stdin.readlines() | |
print("Read {} lines from STDIN.".format(len(lines))) | |
print("Line {:<3}: {:<30} | {:<30}".format("N", "STDIN", "to lower")) | |
print("{:-<7} : {:-<30} | {:-<30}".format("", "", "")) | |
for cnt, line in enumerate(lines): | |
pline = line[:30] | |
print("Line {:<3}: {:<30} | {:<30}".format(cnt, | |
pline.strip(), | |
pline.strip().lower())) | |
print() | |
print("Number of args passed: {}".format(len(sys.argv))) | |
for cnt, arg in enumerate(sys.argv): | |
print("{}: {}".format(cnt, arg)) | |
EOF | |
) $@ | |
} | |
echo -e 'THIS IS A VERY LONG LINE OF TEXT THAT IS CUTTED\nSMALL LINE\nCONVERTED TO LOWCASE' | python_code_in_bash arg1 arg2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment