Mail Archives: cygwin/2006/11/08/18:35:26
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 -