All of lore.kernel.org
 help / color / mirror / Atom feed
* setvar MIA?
@ 2011-01-11 15:54 Aragon Gouveia
  2011-01-11 16:10 ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Aragon Gouveia @ 2011-01-11 15:54 UTC (permalink / raw)
  To: dash

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setvar MIA?
  2011-01-11 15:54 setvar MIA? Aragon Gouveia
@ 2011-01-11 16:10 ` Eric Blake
  2011-01-11 16:54   ` Aragon Gouveia
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2011-01-11 16:10 UTC (permalink / raw)
  To: Aragon Gouveia; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

On 01/11/2011 08:54 AM, Aragon Gouveia wrote:
> 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?

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setvar MIA?
  2011-01-11 16:10 ` Eric Blake
@ 2011-01-11 16:54   ` Aragon Gouveia
  2011-01-11 17:00     ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Aragon Gouveia @ 2011-01-11 16:54 UTC (permalink / raw)
  To: Eric Blake; +Cc: dash

Hi,

On 01/11/11 18:10, Eric Blake wrote:
> 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:

http://www.freebsd.org/cgi/man.cgi?query=sh&apropos=0&sektion=0&manpath=FreeBSD+8.1-RELEASE&format=html

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setvar MIA?
  2011-01-11 16:54   ` Aragon Gouveia
@ 2011-01-11 17:00     ` Eric Blake
  2011-01-11 19:58       ` Jilles Tjoelker
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2011-01-11 17:00 UTC (permalink / raw)
  To: Aragon Gouveia; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

On 01/11/2011 09:54 AM, Aragon Gouveia wrote:
> 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.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setvar MIA?
  2011-01-11 17:00     ` Eric Blake
@ 2011-01-11 19:58       ` Jilles Tjoelker
  0 siblings, 0 replies; 5+ messages in thread
From: Jilles Tjoelker @ 2011-01-11 19:58 UTC (permalink / raw)
  To: Eric Blake; +Cc: Aragon Gouveia, dash

On Tue, Jan 11, 2011 at 10:00:33AM -0700, Eric Blake wrote:
> On 01/11/2011 09:54 AM, Aragon Gouveia wrote:
> > 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.

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.

-- 
Jilles Tjoelker

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-11 19:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-11 15:54 setvar MIA? Aragon Gouveia
2011-01-11 16:10 ` Eric Blake
2011-01-11 16:54   ` Aragon Gouveia
2011-01-11 17:00     ` Eric Blake
2011-01-11 19:58       ` Jilles Tjoelker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.