X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: Re: CASE error in script file Date: Wed, 8 Nov 2006 23:34:36 +0000 (UTC) Lines: 36 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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: List-Archive: List-Post: List-Help: , 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 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/