This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CASE error in script file

Shankar Unni <shankarunni <at>> 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:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]