Last active
November 1, 2019 19:52
-
-
Save tateisu/391d33293ac1a874a35b13206efc0a74 to your computer and use it in GitHub Desktop.
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/ash | |
echo "count=$#, 1=$1, 2=$2" |
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/ash | |
print(){ | |
echo "count=$#, 1=$1, 2=$2" | |
} | |
CMD="print" | |
# CMD= "./print.sh" | |
################################### | |
# $(test && echo) を使う場合 | |
echo "testing test && echo ..." | |
eval "$CMD $(true && echo \"--a --b\")" | |
eval "$CMD \"$(true && echo --a --b)\"" | |
eval "$CMD $(false && echo \"--a --b\")" | |
eval "$CMD \"$(false && echo --a --b)\"" | |
# NG 空の引数ができてしまう | |
################################### | |
# 一時変数を使う場合 | |
echo "testing temporary variable..." | |
if true ;then | |
HEADER='"--a --b"' | |
else | |
HEADER= | |
fi | |
eval "$CMD $HEADER" | |
if false ;then | |
HEADER='"--a --b"' | |
else | |
HEADER= | |
fi | |
eval "$CMD $HEADER" |
sh -c だと関数呼び出しに使いにくいのでevalにした
どちらも変数展開が再度行われるなどあり、危険性は高い
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sh -c "..." か eval "" を使うことでコマンド文字列の解釈が再度行われる