Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

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

Writer Emily Wong

My script code is:

var="/some/path"
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

When you use "$var*" the output will be /some/path*, where * is considered as a character (not as a regex expression, since it's inside the double quotes). 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 regex pattern, meaning anything that starts with path (path1, path2 etc).
Or if path/* (anything that is on that directory).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy