Re: pad with '0'

From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 07/16/03


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


Relevant Pages

  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... One of the biggest advantages of Unix-like shells ... > flexible as the Unix scripts using the more powerful ... about bash, which being a fully-capable shell, can launch programs ... > execute the com program itself). ...
    (alt.lang.asm)
  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... > if people have been discussing the unix ... One of the biggest advantages of Unix-like shells ... better Unix-like shells (sh, csh, bash, ...) used in Unix/Linux ... that scripts in DOS/Windows (using the less ...
    (alt.lang.asm)
  • Re: problems with .bashrc
    ... Seems like bash isn't reading the rc file. ... I think what is happening is the aliases in .shrc are not read directly by ... Non-login interactive bash shells (when changing or starting new shells ...
    (freebsd-questions)
  • Re: Shell Games
    ... Here is a link that explains shells ... >Scripting languages like PERL and Bash serve diffrent ... I do alot of Bash scripting to automate alot ... Switch to Netscape Internet Service. ...
    (freebsd-newbies)
  • bash
    ... GNU bash, version 2.05b.0-release- ... executed by bashfor login shells. ... # include .bashrc if it exists ... However this makes the meta key not work as a meta key, ...
    (Debian-User)