From: Dominic Fandrey on
On 15/03/2010 08:26, Stephane CHAZELAS wrote:
> 2010-03-14, 21:35(+01), Dominic Fandrey:
> [...]
>> # Checks whether the given parameter is an integer.
>> # Integers may be signed, but there must not be any spaces.
>> #
>> # @param 1
>> # The parameter to check.
>> # @return
>> # 0 for integers, 1 for everything else.
>> #
>> isInt() {
>> echo "$1" | egrep -qxe "(-|\+)?[0-9]+"
>> }
> [...]
>
> 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
$ echo "\062" | egrep -qxe "(-|\+)?[0-9]+"
$ echo $?
1
$

echo is not printf.

--
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
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.

With a Unix conformant echo, you'd get:

$ echo '\062'
2

--
Stéphane
From: Dominic Fandrey on
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"?

--
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
2010-03-16, 15:14(+01), Dominic Fandrey:
> 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?

as per POSIX, the behavior of echo "\062" is unspecified which
allows non-Unix but mostly POSIX shells like bash to output
"\062". Unix (includes the XSI option in the Single Unix
Specification).

In a script intended for Unix conformant systems, you can write
echo -n "\062" and be guaranteed that it will output "-n 2<LF>".

If you want to broaden the compatibility of your script to Unix
shs but also the other POSIX ones, you cannot use "echo -n
"\062"", in your script because the behavior is unspecified.

But you can use printf -- '-n \62\n' and be guaranteed that

> Well, I don't really care about that. POSIX doesn't even define
> "local". How would anyone write shell scripts without "local"?

I don't understand what you're trying to say.

You can use "local" in your scripts as long as you don't want
your script to be portable, or only portable to certains
versions of some implementations of some shells, the list of
which is not going to be easy to find out. Or as the LSB
specifies "local", your script could be portable to LSB
conformant shells/systems.

If you stick to a POSIX syntax, then it becomes clear where your
script is going to work. And if it doesn't work on a POSIX
system, then that system is to blame not your script.

You can implement "local" scope with a POSIX syntax, see for
instance http://stchaz.free.fr/locvar.sh as a proof of concept.

In any shell, local scope can be achieved using subshells.

If you do need local scope badly, then chances are that you need
a real programming language, not a shell.

--
Stéphane
From: pk on
Dominic Fandrey wrote:

>> 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"?

Lots of people have done that for years and still do.