Question

I have an trouble with cygwin and qoutemarks.

This works:

grep FOO /path/to/files\ with\ spaces/*
grep FOO "/path/to/files with spaces/file1.txt"

But this does not:

grep FOO "/path/to/files with spaces/*"  
grep FOO '/path/to/files with spaces/*'

The error messange is: grep: /path/to/files with spaces/*: No such file or directory

It the asterisk interpreted in some special way or am I missing something completely obvious, or is something weird going on.

Was it helpful?

Solution

Are you running inside bash? man bash for the full details.

Basically, wildcard expansion is done by the shell in unix, not by the commands themselves. Let's say that I have four files, a, b, c and d in my folder. set -x tells bash to echo the command it is actually going to attempt to run after it has munged what you typed, so we'll use that here.

$ set -x
$ echo *
+ echo a b c d
a b c d

That line starting + is printed by bash: bash actually passes a b c d to echo. echo never sees the * you typed.

$ echo "*"
+ echo '*'
*

This time you told bash not to do filename expansion on the * by quoting it. Thus echo now sees the *.

As for your original query, try

grep FOO '/path/to/files with spaces/'*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top