From b41b9028d447fbd0444824280d53e2b28e8355ad Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 24 Mar 2016 21:04:15 -0400 Subject: research/ref.sh: New file --- diff --git a/research/ref.sh b/research/ref.sh new file mode 100644 index 0000000..88f1d31 --- /dev/null +++ b/research/ref.sh @@ -0,0 +1,66 @@ +foo() +{ + local var=1 + + bar var +} + +bar(string ref) +{ + local var=2 + + eval "${ref}=3" +} + + + +foo() +{ + local var=1 + + bar &var +} + +bar(string ref) +{ + local var=2 + + !ref=3 +} + + + +__ref() +{ + __var=${1} + + case " ${__fn_vars} " in *" ${__var} "*) + printf '__fn_vars_%d_%s' ${__sp} "${__var}" + return 0 + ;; esac + eval "__val=\${__${__prev_tu}_static_vars}" + case " ${__val} " in *" ${__var} "*) + printf '__fn_vars_%d_%s' ${__sp} "${__var}" + return 0 + ;; esac +} + +__derefset() +{ + __var=${1} + + case "${__var}" in + *[!A-Za-z0-9_]*) + printf 'Error: Invalid reference variable\n' >&2 + exit 1 + ;; + '__fn_vars_'[A-Za-z_]*) + ;; + *) + printf 'Error: Invalid reference variable\n' >&2 + exit 1 + ;; + esac + + eval "printf '%s' \${${__var#__fn_vars_}}" +} -- cgit v0.9.1