An interesting little quirk - difference between "bash" and "dash" (Linux)

Liste des GroupesRevenir à cu shell 
Sujet : An interesting little quirk - difference between "bash" and "dash" (Linux)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 05. Jan 2025, 13:04:59
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vldshb$2jmh6$1@news.xmission.com>
User-Agent : trn 4.0-test77 (Sep 1, 2010)
Consider these two command lines (run from a bash shell, but that's
actually not relevant):

$ bash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo =
$ dash -c 'foo=bar;myfun() { local foo; echo "In myfun(), foo = $foo"; };myfun'
In myfun(), foo = bar
$

The difference is that in dash, the local foo picks up the value of the
global foo, while in bash, it is empty.

I'm not standards obsessed like some people in these newsgroups; I care
more about desirable functionality.  In this case, I would not be surprised
to hear that the dash behavior is more POSIX-ly correct, but it seems clear
to me that the bash behavior is more desirable.

I frequently use "local" precisely to ensure that I get a fresh,
un-initialized variable.  Yes, I know that you can always do: local foo=''
but that takes the fun out of it.

--
BigBusiness types (aka, Republicans/Conservatives/Independents/Liberatarians/whatevers)
don't hate big government. They *love* big government as a means for them to get
rich, sucking off the public teat. What they don't like is *democracy* - you know,
like people actually having the right to vote and stuff like that.

Date Sujet#  Auteur
5 Jan 25 * An interesting little quirk - difference between "bash" and "dash" (Linux)6Kenny McCormack
5 Jan 25 +- Re: An interesting little quirk - difference between "bash" and "dash" (Linux)1Kaz Kylheku
5 Jan 25 +- Re: An interesting little quirk - difference between "bash" and "dash" (Linux)1Jerry Peters
5 Jan 25 +- Re: An interesting little quirk - difference between "bash" and "dash" (Linux)1Helmut Waitzmann
5 Jan 25 `* Re: An interesting little quirk - difference between "bash" and "dash" (Linux)2Christian Weisgerber
6 Jan 25  `- Re: An interesting little quirk - difference between "bash" and "dash" (Linux)1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal