setvar MIA?
Hi,
I'm working on making a number of shell scripts cross compatible between FreeBSD and Linux, but one thorn in my side has been dash's lack of a setvar builtin. Does anyone know if this is a work in progress, or a decidedly void feature in dash?
Thanks,
Aragon
Quoted 6 lines · Aragon Gouveia
Hi,
I'm working on making a number of shell scripts cross compatible between FreeBSD and Linux, but one thorn in my side has been dash's lack of a setvar builtin. Does anyone know if this is a work in progress, or a decidedly void feature in dash?
Decidedly missing. POSIX doesn't require it. Neither bash nor ksh provides setvar as a builtin, either. And what does setvar do anyways?
Perhaps it is some alias or shell function that you have inherited from
startup files in one of your other shells, but I've never heard of a 'setvar' program. So why bloat dash to include it?
Signature · 2 lines
Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
Hi,
Quoted 5 lines · Eric Blake
Decidedly missing. POSIX doesn't require it. Neither bash nor ksh provides setvar as a builtin, either. And what does setvar do anyways?
Perhaps it is some alias or shell function that you have inherited from
startup files in one of your other shells, but I've never heard of a 'setvar' program. So why bloat dash to include it?
It is a builtin in FreeBSD's Bourne shell:
I wasn't sure of its status in POSIX. It is useful for declaring variable variables - tidier than eval and I imagine faster, eg.
index="1"
setvar var_${index} "value"
Will emulate it with a local function - thanks.
Regards,
Aragon
Quoted 7 lines · Aragon Gouveia
I wasn't sure of its status in POSIX. It is useful for declaring variable variables - tidier than eval and I imagine faster, eg.
index="1"
setvar var_${index} "value"Will emulate it with a local function - thanks.
Indeed, it looks like FreeBSD introduced it as shorthand for:
setvar() { eval $1=\$2; }
The speed difference between that function doing an eval and a shell builtin would be in the noise. I don't know why FreeBSD even bothered to pollute the namespace with a builtin like that.
Signature · 2 lines
Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
Quoted 9 lines · Eric Blake
Quoted 7 lines · Aragon Gouveia
I wasn't sure of its status in POSIX. It is useful for declaring variable variables - tidier than eval and I imagine faster, eg.
index="1"
setvar var_${index} "value"Will emulate it with a local function - thanks.
Quoted 7 lines
Indeed, it looks like FreeBSD introduced it as shorthand for:
setvar(){ eval $1=\$2; }The speed difference between that function doing an eval and a shell builtin would be in the noise. I don't know why FreeBSD even bothered to pollute the namespace with a builtin like that.
The setvar builtin was already present and documented in the initial ash. FreeBSD simply inherited it. Dash inherited it too, but it was removed in dash-0.4.14, 3 Apr 2003.
The use of Almquist's additions like this one is certainly questionable; many of them have been removed. However, setvar has been available and documented in /bin/sh in all versions of FreeBSD, which makes removal less likely at this point.
Signature · 1 line
Jilles Tjoelker