How to handle numeric variables in sh?

Ask a Question related to FreeBSD, Design and Development.

  1. #1

    Default Re: How to handle numeric variables in sh?

    Here's a code snippet of a script I use often to number a bunch of pics
    in a directory that I think shows how to do what you want to do:

    $PICNUM=100
    for FNAME in DSC*.JPG
    do
    NEWNAME=My_Pictures-$PICNUM.jpg
    mv $FNAME $NEWNAME
    PICNUM=$(($PICNUM+1))
    done

    This works in /bin/sh from my FreeBSD 4.11 system and also bash. If you
    want to perform a mathematical operation on a shell variable, just
    surround the expression with $(( expr )) and it'll work.

    Hope that helps.

    Scott Milliken

    Alejandro Pulver wrote:
    >Hello,
    >
    >Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    >
    >Thanks and Best Regards,
    >Ale
    >_______________________________________________
    >freebsd-questions@freebsd.org mailing list
    >[url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    >To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    >
    >!DSPAM:42176184998836675110134!
    >
    >
    >
    Scott Milliken Guest

  2. Similar Questions and Discussions

    1. #39447 [NEW]: Want to optionally handle apc_upload_progress variables using session variables
      From: krudtaa at yahoo dot com Operating system: All PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug...
    2. Numeric stepper
      I have a Numeric stepper & values are set as 1 min & 10000 max. The problem is - In the control if I clear the value (There is no value in the...
    3. JRun fails to handle client variables in DB over 8K
      We are in the process of upgrading from CF 4.5 to CF MX 7. Our application uses client variables, which are configured to be stored in a SQL...
    4. how to handle 64 bit variables on 32 bit machines ?
      Hi, I'd like to use the ruby/dl library to access function in a C library from ruby. Now these functions take 64 bit parameters und my machine...
    5. ViewState can't handle numeric fields?
      If I do this x = 5 ViewState("myX") = x then after a post-back, ViewState("myX") is Nothing but this
  3. #2

    Default How to handle numeric variables in sh?

    Hello,

    Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?

    Thanks and Best Regards,
    Ale
    Alejandro Pulver Guest

  4. #3

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    <alejandro@varnet.biz> wrote:
    > Hello,
    >
    > Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    >
    `man bc`

    --
    If I write a signature, my emails will appear more personalised.
    Eric Kjeldergaard Guest

  5. #4

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 10:07:51 -0600
    Eric Kjeldergaard <kjelderg@gmail.com> wrote:
    > On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    > <alejandro@varnet.biz> wrote:
    > > Hello,
    > >
    > > Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    > >
    >
    > `man bc`
    >
    > --
    > If I write a signature, my emails will appear more personalised.
    > _______________________________________________
    > [email]freebsd-questions@freebsd.org[/email] mailing list
    > [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    Thank You.

    Best Regards,
    Ale
    Alejandro Pulver Guest

  6. #5

    Default Re: How to handle numeric variables in sh?

    Ale:


    On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    <alejandro@varnet.biz> wrote:
    > Hello,
    >
    > Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    Here is a good short "HowTo" on calling bc:
    -----------------------------------------------------------------
    >> Shell Tip: Calculating with large numbers using "bc"
    -----------------------------------------------------------------
    [url]http://www.shelldorado.com/newsletter/issues/2002-3-Aug.html[/url]

    Shelldorado is a great reference site:

    [url]http://www.shelldorado.com/[/url]
    Jon Drews Guest

  7. #6

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 10:24:04 -0500
    Scott Milliken <scott.milliken@e-comsultant.net> wrote:
    > Here's a code snippet of a script I use often to number a bunch of pics
    > in a directory that I think shows how to do what you want to do:
    >
    > $PICNUM=100
    > for FNAME in DSC*.JPG
    > do
    > NEWNAME=My_Pictures-$PICNUM.jpg
    > mv $FNAME $NEWNAME
    > PICNUM=$(($PICNUM+1))
    > done
    >
    > This works in /bin/sh from my FreeBSD 4.11 system and also bash. If you
    > want to perform a mathematical operation on a shell variable, just
    > surround the expression with $(( expr )) and it'll work.
    >
    > Hope that helps.
    >
    > Scott Milliken
    >
    Thank You.

    Y saw the use of '$(( expr ))' some time ago in 'Advanced Bash Scripting Guide', but I thought it was only for 'bash'.

    I am using FreeBSD 5.3 and it also works in '/bin/sh'.

    Best Regards,
    Ale
    Alejandro Pulver Guest

  8. #7

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 09:33:11 -0700
    Jon Drews <jon.drews@gmail.com> wrote:
    > Ale:
    >
    >
    > On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    > <alejandro@varnet.biz> wrote:
    > > Hello,
    > >
    > > Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    >
    > Here is a good short "HowTo" on calling bc:
    > -----------------------------------------------------------------
    > >> Shell Tip: Calculating with large numbers using "bc"
    > -----------------------------------------------------------------
    > [url]http://www.shelldorado.com/newsletter/issues/2002-3-Aug.html[/url]
    >
    > Shelldorado is a great reference site:
    >
    > [url]http://www.shelldorado.com/[/url]
    > _______________________________________________
    > [email]freebsd-questions@freebsd.org[/email] mailing list
    > [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    Interesting site.

    Thank You.

    Best Regards,
    Ale
    Alejandro Pulver Guest

  9. #8

    Default Re: How to handle numeric variables in sh?

    hi,

    have a look at "man expr"

    regards

    Alejandro Pulver wrote:
    > Hello,
    >
    > Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    >
    > Thanks and Best Regards,
    > Ale
    > _______________________________________________
    > [email]freebsd-questions@freebsd.org[/email] mailing list
    > [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    >
    JarJarBings Guest

  10. #9

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 20:16:23 +0100
    JarJarBings <jarjarbings@aon.at> wrote:
    > hi,
    >
    > have a look at "man expr"
    >
    > regards
    >
    > Alejandro Pulver wrote:
    > > Hello,
    > >
    > > Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
    > >
    > > Thanks and Best Regards,
    > > Ale
    Thank You.

    Bests Regards,
    Ale
    Alejandro Pulver Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139