This is the mail archive of the
mailing list for the Cygwin project.
Re: <<expr 100 * 100>> returns syntax error
- From: Adam Dinwoodie <adam at dinwoodie dot org>
- To: cygwin at cygwin dot com
- Date: Thu, 28 Jul 2016 14:14:17 +0100
- Subject: Re: <<expr 100 * 100>> returns syntax error
- Authentication-results: sourceware.org; auth=none
- References: <firstname.lastname@example.org>
On Thu, Jul 28, 2016 at 12:55:43PM +0000, email@example.com wrote:
> Steps to reproduce (I cannot update cygwin on this server, but it also happen on 2.5.2(0.297/5/3)):
> Main window:
> $ uname -r
> $ expr 100 * 100
> Other window:
> $ $ uname -r
> $ HOST=myhostname
> $ echo 'whatever' > $HOST.txt
> Main window:
> $set -xv
> $expr 100 * 100
> + expr 100 myhostname.txt 100
> syntax error
> When this happen I can only fix by rebooting the server, which is obviously unideal!
> Here my questions:
> 1) How can I reset cygwin to the initial behaviour without rebooting?
> 2) why does this happen? how to prevent this?
This is working as intended: '*' is a shell glob character, so Bash will
attempt to expand it.
In the first case, you're evidently in a directory that contains no
files or directories (excluding ones that start with a '.'), so the glob
doesn't expand and is left as-is. This means the `expr` command sees
the arguments as you typed them: `100 * 100`.
In the second case, you've created a file called myhostname.txt in this
directory, so the '*' glob will expand to the list of matching file
names, i.e. myhostname.txt. This means the `expr` command will see the
arguments after the glob expansion, i.e. `100 myhostname.txt 100`.
Run the following commands in a shell and you might see what's
mkdir tmp; cd tmp
See also https://en.wikipedia.org/wiki/Glob_(programming)
You can disable this behaviour with `set -f`, or by escaping or quoting
the '*' character (i.e. `expr 100 \* 100` or `expr 100 '*' 100`).
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple