Prev: Parsing "for" clause
Next: read multiple fields separated by : and fields separated by , in loop stored in $var
From: Seebs on 16 Mar 2010 11:35 On 2010-03-16, pk <pk(a)pk.invalid> wrote: > Dominic Fandrey wrote: >> Well, I don't really care about that. POSIX doesn't even define >> "local". How would anyone write shell scripts without "local"? > Lots of people have done that for years and still do. I only know what it does 'cuz of writing a book on shell portability. It wouldn't have occurred to me. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Janis Papanagnou on 16 Mar 2010 13:34 Dominic Fandrey wrote: > On 15/03/2010 18:56, Stephane CHAZELAS wrote: >> 2010-03-15, 13:36(+01), Dominic Fandrey: >> [...] >>>> That will say that "foo<LF>1" is an integer, or that "\062" is >>>> an integer (with an Unix echo), the result for "12\c" is >>>> unspecified (unterminated line)... >> [...] >>> I cannot follow you here: >>> >>> $ echo "\062" >>> \062 >> Your echo is not Unix conformant. > > You're talking about POSIX? > > Well, I don't really care about that. POSIX doesn't even define > "local". How would anyone write shell scripts without "local"? > In ksh functions I use typeset to declare local variables. The "local" keyword is unknown to that shell. Is "local" available in any shell other than bash? Is "local" in any way "better" than "typeset", or vice versa? Both, local and typeset, are non-standard, certainly shell dependent. That makes your above claim sound silly. Janis
From: Dominic Fandrey on 16 Mar 2010 14:48 On 16/03/2010 18:34, Janis Papanagnou wrote: > Dominic Fandrey wrote: >> On 15/03/2010 18:56, Stephane CHAZELAS wrote: >>> 2010-03-15, 13:36(+01), Dominic Fandrey: >>> [...] >>>>> That will say that "foo<LF>1" is an integer, or that "\062" is >>>>> an integer (with an Unix echo), the result for "12\c" is >>>>> unspecified (unterminated line)... >>> [...] >>>> I cannot follow you here: >>>> >>>> $ echo "\062" >>>> \062 >>> Your echo is not Unix conformant. >> >> You're talking about POSIX? >> >> Well, I don't really care about that. POSIX doesn't even define >> "local". How would anyone write shell scripts without "local"? >> > > In ksh functions I use typeset to declare local variables. The "local" > keyword is unknown to that shell. Is "local" available in any shell > other than bash? Is "local" in any way "better" than "typeset", or > vice versa? Both, local and typeset, are non-standard, certainly shell > dependent. That makes your above claim sound silly. So ksh has something similar to local. Just proves that the thing is required, at least in my book. It looks like typeset is more portable, but ASH doesn't know it, so it's of no use to me. Recursive functions, without local or your typeset thing? That doesn't sound nice to me. Imagine you have ~100 functions and need to make up distinct variable names for each one? You end up with annoying prefixes and still haven't solved the recursion problem. The feature is needed and POSIX doesn't define it. If you stick to POSIX you're stuck. Regards -- A: Because it fouls the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
From: Stephane CHAZELAS on 16 Mar 2010 15:02 2010-03-16, 19:48(+01), Dominic Fandrey: [...] >> In ksh functions I use typeset to declare local variables. The "local" >> keyword is unknown to that shell. Is "local" available in any shell >> other than bash? Is "local" in any way "better" than "typeset", or >> vice versa? Both, local and typeset, are non-standard, certainly shell >> dependent. That makes your above claim sound silly. > > So ksh has something similar to local. Just proves that the thing > is required, at least in my book. It looks like typeset is more > portable, but ASH doesn't know it, so it's of no use to me. The original ash doesn't know "local" either. debian added it to its variant of ash so that it is LSB compliant. "local" is in dash, bash, zsh, pdksh and its derivatives. It's in the LSB (Linux Software Base) specification, though you may only use it as: local var (no local var=value). > Recursive functions, without local or your typeset thing? > That doesn't sound nice to me. > > Imagine you have ~100 functions and need to make up distinct variable > names for each one? You end up with annoying prefixes and still > haven't solved the recursion problem. A shell script with ~100 functions? That's wasting your energy and time and that of whomever's going to try and maintain your script after you're gone. Shells weren't designed for that. -- Stéphane
From: Stephane CHAZELAS on 16 Mar 2010 15:14
2010-03-16, 19:02(+00), Stephane CHAZELAS: > 2010-03-16, 19:48(+01), Dominic Fandrey: > [...] >>> In ksh functions I use typeset to declare local variables. The "local" >>> keyword is unknown to that shell. Is "local" available in any shell >>> other than bash? Is "local" in any way "better" than "typeset", or >>> vice versa? Both, local and typeset, are non-standard, certainly shell >>> dependent. That makes your above claim sound silly. >> >> So ksh has something similar to local. Just proves that the thing >> is required, at least in my book. It looks like typeset is more >> portable, but ASH doesn't know it, so it's of no use to me. > > The original ash doesn't know "local" either. debian added it to > its variant of ash so that it is LSB compliant. [...] Sorry, please ignore the above. "local" was in the original ash (http://groups.google.com/group/comp.sources.unix/msg/2774e7653a8e6274) from 1989, I must have confused with something else. Which probably makes it the first shell to have that builtin (local scope was implemented in ksh before that though). As a result, all the BSD shs (based either on ash or pdksh) must have "local" as well. -- Stéphane |