From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21628 invoked by alias); 29 Jan 2009 23:08:29 -0000 Received: (qmail 21618 invoked by uid 22791); 29 Jan 2009 23:08:28 -0000 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 Received: from mail2.panix.com (HELO mail2.panix.com) (166.84.1.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Jan 2009 23:08:24 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mail2.panix.com (Postfix) with ESMTP id 6868D3480B for ; Thu, 29 Jan 2009 18:08:22 -0500 (EST) Received: by panix2.panix.com (Postfix, from userid 19362) id 0EF651A403; Thu, 29 Jan 2009 18:08:23 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by panix2.panix.com (Postfix) with ESMTP id 0B4FA1AC07 for ; Thu, 29 Jan 2009 17:08:23 -0600 (CST) Date: Fri, 30 Jan 2009 00:51:00 -0000 From: Tim McDaniel cc: cygwin@cygwin.com Subject: Re: Setting Integer Variables in Bash In-Reply-To: <21737864.post@talk.nabble.com> Message-ID: References: <21737864.post@talk.nabble.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: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2009-01/txt/msg00873.txt.bz2 On Thu, 29 Jan 2009, whitewall wrote: > The text below is from a text file. If I type the commands > line-by-line in the bash then the commands work as expected. If I > save the commands in a text file and call the script I get the error > message: > ': not a valid identifier2: declare: 'Red > ': not a valid identifier3: declare: 'Green Two error messages. > #! /cygdrive/c/cygwin/bin/bash > declare -i Red > declare -i Green > Red=10 > Green=$Red+1 > echo $Green > exit 0 You have a carriage return at the end of each line. bash does NOT consider carriage return to be whitespace, dammit, so it is considered normal characters. So it things, for example, that you're declaring a variable named "Red\r", a four-character name, and it just doesn't allow carriage return in the variable name. The key to recognizing the situation is to see ': not a valid identifier2: declare: 'Red and recognize that there's a carriage return in the middle of the message. The opening ' is just before Red. Its matching closing ' is shown as the start of the line -- because carriage return causes the output display to return to the start of line. So - by default, created files in UNIX file format, not native Windows. - strip out the carriage returns from your existing script -- 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/