X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 	tests=AWL,BAYES_00,MISSING_HEADERS,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
Date: Thu, 29 Jan 2009 18:51:25 -0600 (CST)
From: Tim McDaniel <tmcd@panix.com>
cc: cygwin@cygwin.com
Subject: Re: Setting Integer Variables in Bash
In-Reply-To: <f60fe000901291540o62d155c5sa47004f8cfe8c750@mail.gmail.com>
Message-ID: <Pine.NEB.4.64.0901291846010.1979@panix2.panix.com>
References: <21737864.post@talk.nabble.com> <f60fe000901291540o62d155c5sa47004f8cfe8c750@mail.gmail.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Thu, 29 Jan 2009, Mark J. Reed wrote:
> On Thu, Jan 29, 2009 at 5:54 PM, whitewall wrote:
>> #! /cygdrive/c/cygwin/bin/bash
>> declare -i Red
>> declare -i Green
>> Red=10
>> Green=$Red+1
>
> Since you've declared both Green and Red as integer, you should just
> do Green=Red+1, without the dollar sign. Doing Green=$Red+1 first
> takes Red's value, which is stored as an integer, expands it back
> into its decimal string representation, and then reparses it to
> yield its integer value.

There IS one subtle difference.  If you're running with "set -x",
     Green=$Red+1
will echo
     + Green=10+1
But
     Green=Red+1
will echo
     + Green=Red+1
(assuming that you've not changed PS4, IFS, &c &c).  You can decide
which "set -x" output you like.  I found that I preferred the
substituted forms, the ones with $this and $that.

-- 
Tim McDaniel, tmcd@panix.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

