delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT 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 17:08:23 -0600 (CST) |
From: | Tim McDaniel <tmcd AT panix DOT com> |
cc: | cygwin AT cygwin DOT com |
Subject: | Re: Setting Integer Variables in Bash |
In-Reply-To: | <21737864.post@talk.nabble.com> |
Message-ID: | <Pine.NEB.4.64.0901291704240.15614@panix2.panix.com> |
References: | <21737864 DOT post AT talk DOT nabble DOT com> |
MIME-Version: | 1.0 |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Unsubscribe: | <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
On Thu, 29 Jan 2009, whitewall <thewhitewall AT live DOT co DOT uk> 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 AT panix DOT 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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |