Re: pad with '0'
From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 07/16/03
- Next message: Faux_Pseudo: "Re: Call for input on comp.unix.shell FAQ"
- Previous message: Michael Wang: "Re: pad with '0'"
- In reply to: Michael Wang: "Re: pad with '0'"
- Next in thread: Michael Wang: "Re: pad with '0'"
- Reply: Michael Wang: "Re: pad with '0'"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 16 Jul 2003 05:48:15 GMT
On Wed, 16 Jul 2003 at 04:25 GMT, Michael Wang wrote:
> In article <bf2bg6$9o5tj$1@ID-136730.news.uni-berlin.de>,
> Chris F.A. Johnson <c.f.a.johnson@rogers.com> wrote:
>>
>> A person using your function should check that there are no name
>> collisions. You can help by providing a list in the documentation.
>
> Well, I find it easier just trash the POSIX function, and use
> KSH style function.
>
>> There is no Bourne-type shell where "SECONDS=0" will not work;
>> "(( SECONDS = 0 ))" will not work in many of them. Why hobble your
>> script?
>
> If I write ksh program, it would not matter whether "(( SECONDS = 0 ))"
> works under Bourne shell, or any of the other shells.
>
> "SECONDS=0" and "(( SECONDS = 0 ))" are conceptually different things.
>
> SECONDS=0xff
> (( SECONDS = 0xff ))
>
> you will see the difference.
But there is no difference.
If one works, so will the other. Neither works in ksh88, for
example; both work in bash.
> "(( SECONDS = 0 ))" indicates that
> SECONDS is treated as a number.
If it's recognized as a number, it doesn't matter which method you
use (using bash):
$ q=0xff
$ echo $(( $q + 3 ))
258
... if it's not, neither method will work; e.g., (ksh88):
$ q=0xff
$ echo $(( $q + 3 ))
ksh: 0xff + 3 : bad number
$ (( q = 0xff ))
ksh: 0xff : bad number
> If you use things like
>
> (( total += SECONDS ))
I don't, because it's less portable than:
total=$(( $total + $SECONDS ))
> you want to make things consistent.
Indeed; but I also want to make things as portable as possible,
especially when posting in this newsgroup, whose denizens use many
different shells.
The only time I use a non-generic syntax is when there is no good
alternative.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Faux_Pseudo: "Re: Call for input on comp.unix.shell FAQ"
- Previous message: Michael Wang: "Re: pad with '0'"
- In reply to: Michael Wang: "Re: pad with '0'"
- Next in thread: Michael Wang: "Re: pad with '0'"
- Reply: Michael Wang: "Re: pad with '0'"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|