My script code is:

cp "$var*" "/another/path"

Then it throws:

cp: cannot stat '/some/path/*': No such file or directory

I have tried this and got the same error:

cp "${var}*" "/another/path"

Finally, I solved this problem by:

cp "$var"* "/another/path"

This time the command executes successfully, but I'd like to know WHY.

Could you please give out an explanation ?

1 Answer 1


When you use "$var*" the output will be /some/path*, where * is considered as a character (not as a wildcard, since it's inside the double quotes - see globs). So in your case (/some/path/*), cp is searching for a file/folder named * inside the path directory.

When it's outside the double quotes it's considered as a wildcard, meaning anything that starts with path (path1, path2 etc).
Or if path/* (anything that is on that directory).

  • globs are globs, not regular expressions
    – CervEd
    Jun 1, 2023 at 14:39
  • 1
    @CervEd thanks for your message! Changed it to wildcard (was not familiar if it was a wildcard or regex at the time of writing).
    – Erlis D.
    Jun 10, 2023 at 1:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .