Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A way to untie -T vars?
- X-seq: zsh-users 28697
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: A way to untie -T vars?
- Date: Sat, 21 Jan 2023 10:52:14 -0800
- Archived-at: <https://zsh.org/users/28697>
- In-reply-to: <CAH+w=7bL4txwLp4zFPeDvb6fbYfJV6-mT+S4oFnrJ7cXPZr_Xw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAKc7PVDEmKnY9TiYwaAgvzXEqNhLwZo46paUPjJOz9HsU3_djg@mail.gmail.com> <CAH+w=7YY5F_ZYJgivw9PSjt8PTQ9R+gHF3jnjbBw-LLkEnc2zg@mail.gmail.com> <CAH+w=7bL4txwLp4zFPeDvb6fbYfJV6-mT+S4oFnrJ7cXPZr_Xw@mail.gmail.com>
On Sat, Jan 21, 2023 at 9:11 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> % typeset -a FOO=($FOO) foo=($foo)
Speaking of unorthodoxy ...
% typeset -T FOO foo
% typeset foo=bar
typeset: foo: inconsistent type for assignment
% typeset -i foo=1
% typeset -p FOO foo
typeset: no such variable: FOO
typeset -i foo=1
%
So ... with "typeset" I can forcibly convert a tied scalar to an
array, or an array to an integer, but there's no way to convert an
array to an ordinary scalar.
Anyway ...
untie () {
emulate -L zsh
case ${(tP)1} in
(scalar-tied)
local scalar=${(P)1}
unset $1
typeset -g $1=$scalar
;;
(array-tied)
local array=( ${(P)1} )
unset $1
# Need eval here for array assignment, as
# reserved word doesn't work with $1=(...)
eval "typeset -ga $1=( \$array )"
;;
(*) ;;
esac
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author