delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/11/08/18:35:26

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: Re: CASE error in script file
Date: Wed, 8 Nov 2006 23:34:36 +0000 (UTC)
Lines: 36
Message-ID: <loom.20061109T002425-562@post.gmane.org>
References: <loom DOT 20061108T225533-24 AT post DOT gmane DOT org> <eitkmk$d9b$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

Shankar Unni <shankarunni <at> netscape.net> writes:

> 
> Doug wrote:
> 
> > case $1 in
> 
> If $1 is undefined (i.e. you pass in no arguments), this line becomes
> 
>     case  in
> 
> which is incorrect syntax, of course. Answer: quote the "$1".

Quit spreading misinformation.

POSIX requires that token parsing take place BEFORE parameter expansion.  It 
also states that the first argument to case does not undergo token splitting.  
So even if your parameter is empty or undefined, you already have a valid 
parse, so that is not the cause of the reported syntax error.  In fact, you are 
also adding fuel to the incorrect flame that the first token after case must be 
quoted.  NOT SO.  The test string only needs quoting if, without quoting, it 
would not be recognized as a single token in the grammar; the two characters $1 
form a single token, even if its expansion contains spaces, so quotes do 
absolutely nothing for you in this example.

Instead, the syntax error is caused by \r: "in\r" is a different token 
than "in", and the second token after 'case' must be 'in' according to the bash 
grammar.  Because you used DOS line endings on a binary mount, the \r was 
interpreted literally, and was used as part of the third token; review the 
archives for why DOS line endings on binary mounts are bad.  Without \r, the 
original script is perfectly legal.

-- 
Eric Blake
volunteer cygwin bash maintainer



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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019