Created
August 7, 2012 09:56
-
-
Save ormaaj/3284124 to your computer and use it in GitHub Desktop.
environment assignment
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
#!/usr/bin/env bash | |
unset -v x y sh | |
while IFS= read -r s; do | |
IFS= declare -a "shells=( $s )" | |
IFS= read -r testCase | |
printf '%s\n%6s%s\n' "$testCase" '' 'x y x y' | |
for sh in "${shells[@]}"; do | |
printf '%-4s: %s\n' "$sh" "$("$sh" -c "$testCase")" | |
done | |
echo | |
done <<"EOF" | |
sh {{b,d}a,po,{,m}k,z}sh bb | |
x= y=${x:=1} sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
sh {{b,d}a,po,{,m}k,z}sh bb | |
x=2 y=2; x= y=${x:=1} sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
sh {{b,d}a,po,{,m}k,z}sh bb | |
y=${x:=1} sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
sh {{b,d}a,po,{,m}k,z}sh bb | |
x=2 y=2; x=1 y=$x sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
sh {{b,d}a,po,{,m}k,z}sh bb | |
x= y=${x:=1} eval 'printf %1s\ %1s "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
sh {{b,d}a,po,{,m}k,z}sh bb | |
[ -n "${ZSH_VERSION+_}" ] && setopt -o POSIX_BUILTINS; f() { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x=1 y= command eval 'y=$x f'; printf ' %1s %1s' "$x" "$y" | |
{{,m}k,z}sh | |
[ -n "${ZSH_VERSION+_}" ] && setopt -o POSIX_BUILTINS; function f { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x=1 y= command eval 'y=$x f'; printf ' %1s %1s' "$x" "$y" | |
{,m}ksh | |
function f { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x= y=${x:=1} f; printf ' %1s %1s' "$x" "$y" | |
{,m}ksh | |
f() { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x= y=${x:=1} f; printf ' %1s %1s' "$x" "$y" | |
EOF | |
# vim: set fenc=utf-8 ff=unix ts=4 sts=4 sw=4 ft=sh nowrap et: |
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
x= y=${x:=1} sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
sh : 1 1 1 | |
bash: 1 1 1 | |
dash: 1 | |
posh: 1 1 | |
ksh : 1 1 | |
mksh: 1 1 | |
zsh : 1 1 | |
bb : 1 | |
x=2 y=2; x= y=${x:=1} sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
sh : 1 1 1 2 | |
bash: 1 1 1 2 | |
dash: 1 2 2 | |
posh: 1 1 2 2 | |
ksh : 1 1 2 2 | |
mksh: 2 2 2 | |
zsh : 1 1 2 2 | |
bb : 1 2 | |
y=${x:=1} sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
sh : 1 1 | |
bash: 1 1 | |
dash: 1 1 | |
posh: 1 1 | |
ksh : 1 1 | |
mksh: 1 1 | |
zsh : 1 | |
bb : 1 1 | |
x=2 y=2; x=1 y=$x sh -c 'printf "%1s %1s" "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
sh : 1 1 2 2 | |
bash: 1 1 2 2 | |
dash: 1 1 2 2 | |
posh: 1 1 2 2 | |
ksh : 1 1 2 2 | |
mksh: 1 2 2 2 | |
zsh : 1 1 2 2 | |
bb : 1 1 2 2 | |
x= y=${x:=1} eval 'printf %1s\ %1s "$x" "$y"'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
sh : 1 1 1 1 | |
bash: 1 1 1 | |
dash: 1 1 1 1 | |
posh: 1 1 1 1 | |
ksh : 1 1 1 1 | |
mksh: 1 1 1 1 | |
zsh : 1 1 | |
bb : | |
[ -n "${ZSH_VERSION+_}" ] && setopt -o POSIX_BUILTINS; f() { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x=1 y= command eval 'y=$x f'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
sh : 1 1 2 2 | |
bash: 1 1 2 2 | |
dash: 1 1 2 2 | |
posh: 1 1 2 2 | |
ksh : 1 1 2 2 | |
mksh: 1 1 2 2 | |
zsh : 1 1 1 1 | |
bb : 2 2 2 2 | |
[ -n "${ZSH_VERSION+_}" ] && setopt -o POSIX_BUILTINS; function f { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x=1 y= command eval 'y=$x f'; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
ksh : 1 1 2 2 | |
mksh: 1 1 2 2 | |
zsh : 1 1 1 1 | |
function f { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x= y=${x:=1} f; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
ksh : 1 1 2 2 | |
mksh: 2 2 2 | |
f() { printf '%1s %1s' "$x" "$y"; }; x=2 y=2; x= y=${x:=1} f; printf ' %1s %1s' "$x" "$y" | |
x y x y | |
ksh : 1 1 1 1 | |
mksh: 1 1 1 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment