Last active
December 30, 2015 15:27
Revisions
-
bersace revised this gist
Dec 30, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ ## In bash, declare a variable script, assign value "#". In python, declare a ## variable scriptd, assign a heredoc containing the bash script. # shellcheck disable=SC2034 script=""" " ## BEGIN BASH # my_sh_func [ARG ...] -
bersace revised this gist
Dec 30, 2015 . No changes.There are no files selected for viewing
-
bersace revised this gist
Dec 30, 2015 . 1 changed file with 19 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,29 +3,33 @@ # # This python script is callable and sourceable by bash. # # lint python with: flake8 --ignore=E225,E265 py.sh # lint bash with: sed '/^## END BASH/,$d' py.sh | shellcheck - ## In bash, declare a variable script, assign value "#". In python, declare a ## variable scriptd, assign a heredoc containing the bash script. # shellcheck disable=SC2034 script="""" ## BEGIN BASH # my_sh_func [ARG ...] # Echo arguments # # my_sh_func toto # my_sh_func() { echo $* } if [[ ${BASH_SOURCE[0]} = $0 ]]; then if declare -f -- "${1-}" >&2; then # When $1 is a bash function, call it and exit. set -eux $* exit 0 else # Any other argument is passed to python script. exec python3 ${BASH_SOURCE[0]} $* fi else echo ${BASH_SOURCE[0]} sourced -
bersace created this gist
Dec 30, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/bin/bash ## -*- python -*- # # This python script is callable and sourceable by bash. # ## In bash, declare a variable script, assign value "#". In python, declare a ## variable script. Assign a heredoc containing the bash script. script="""" ## BEGIN BASH if [[ ${BASH_SOURCE[0]} = $0 ]]; then if [ -z "${1-}" ]; then # Show help sed -E '1d;/^#/!d;/^##/d;s/^# ?//' $0 exit 1 else set -eux fi fi ## BASH FUNCTIONS if [[ ${BASH_SOURCE[0]} = $0 ]]; then if declare -f "$1" >&2; then $@ else exec python3 $0 $* fi else echo ${BASH_SOURCE[0]} sourced return 0 fi ## Assert this statement is not reached in bash. exit 1 ## END BASH """ # " # Close quote for bash syntax highlighting. ## Drop script variable, and begin python script as usual. del script import sys print(sys.argv)