Path: ...!weretis.net!feeder9.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail From: gazelle@shell.xmission.com (Kenny McCormack) Newsgroups: comp.unix.shell Subject: An interesting little quirk - difference between "bash" and "dash" (Linux) Date: Sun, 5 Jan 2025 12:04:59 -0000 (UTC) Organization: The official candy of the new Millennium Message-ID: Injection-Date: Sun, 5 Jan 2025 12:04:59 -0000 (UTC) Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4"; logging-data="2742822"; mail-complaints-to="abuse@xmission.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: gazelle@shell.xmission.com (Kenny McCormack) Bytes: 1980 Lines: 25 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.