Professional Web Applications Themes

How to handle numeric variables in sh? - FreeBSD

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

  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-questionsfreebsd.org mailing list
    >[url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    >To unsubscribe, send any mail to "freebsd-questions-unsubscribefreebsd.org"
    >
    >!DSPAM:42176184998836675110134!
    >
    >
    >
    Scott Milliken Guest

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

  3. #3

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    <alejandrovarnet.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

  4. #4

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 10:07:51 -0600
    Eric Kjeldergaard <kjelderg> wrote:
    > On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    > <alejandrovarnet.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-questionsfreebsd.org[/email] mailing list
    > [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    > To unsubscribe, send any mail to "freebsd-questions-unsubscribefreebsd.org"
    Thank You.

    Best Regards,
    Ale
    Alejandro Pulver Guest

  5. #5

    Default Re: How to handle numeric variables in sh?

    Ale:


    On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    <alejandrovarnet.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

  6. #6

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 10:24:04 -0500
    Scott Milliken <scott.millikene-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

  7. #7

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 09:33:11 -0700
    Jon Drews <jon.drews> wrote:
    > Ale:
    >
    >
    > On Sat, 19 Feb 2005 12:55:59 -0300, Alejandro Pulver
    > <alejandrovarnet.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-questionsfreebsd.org[/email] mailing list
    > [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    > To unsubscribe, send any mail to "freebsd-questions-unsubscribefreebsd.org"
    Interesting site.

    Thank You.

    Best Regards,
    Ale
    Alejandro Pulver Guest

  8. #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-questionsfreebsd.org[/email] mailing list
    > [url]http://lists.freebsd.org/mailman/listinfo/freebsd-questions[/url]
    > To unsubscribe, send any mail to "freebsd-questions-unsubscribefreebsd.org"
    >
    JarJarBings Guest

  9. #9

    Default Re: How to handle numeric variables in sh?

    On Sat, 19 Feb 2005 20:16:23 +0100
    JarJarBings <jarjarbingsaon.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

Similar Threads

  1. Replies: 1
    Last Post: November 11th, 10:35 PM
  2. JRun fails to handle client variables in DB over 8K
    By Emblue in forum Coldfusion Server Administration
    Replies: 9
    Last Post: July 26th, 06:50 PM
  3. how to handle 64 bit variables on 32 bit machines ?
    By Alexander Neundorf in forum Ruby
    Replies: 2
    Last Post: October 28th, 01:06 AM
  4. ViewState can't handle numeric fields?
    By Boban Dragojlovic in forum ASP.NET General
    Replies: 0
    Last Post: June 24th, 03:04 PM
  5. How do I test if a value is numeric?
    By Graeme Richardson in forum Oracle Server
    Replies: 1
    Last Post: December 18th, 02:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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