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).