I'm trying to do a: cp "$src/*.tgz" "$dst/." command in a bash script, where $src and $dst are bash variables containing the path names, which may include blanks in their names. The sources to be moved are all *.tgz files in $src, but the shell script tells me there are none. I believe "parameter expansion" is trumping "pathname expansion" and leaving the asterisk (*) such that "cp" can't interpret it. The same cp-command without quotes works, but only if both $src and $dst are non-blank strings.
How can I accomplish this "cp"?
pbdsl1:~ dickguertin$ cat ab
#!/bin/bash
src="/Users/dickguertin/Desktop/alpha"
dst="/Users/dickguertin/Desktop/beta"
rm -f $dst/*.tgz
cp "$src/*.tgz" "$dst/."
# cp $src/*.tgz $dst/.
exit 0
pbdsl1:~ dickguertin$ ./ab
cp: /Users/dickguertin/Desktop/alpha/*.tgz: No such file or directory
The non-quoted (commented) command works, but only because there are no blanks in the path names. There are alpha and beta directories on the Desktop, and alpha holds several tgz-files.
How can I accomplish this "cp"?
pbdsl1:~ dickguertin$ cat ab
#!/bin/bash
src="/Users/dickguertin/Desktop/alpha"
dst="/Users/dickguertin/Desktop/beta"
rm -f $dst/*.tgz
cp "$src/*.tgz" "$dst/."
# cp $src/*.tgz $dst/.
exit 0
pbdsl1:~ dickguertin$ ./ab
cp: /Users/dickguertin/Desktop/alpha/*.tgz: No such file or directory
The non-quoted (commented) command works, but only because there are no blanks in the path names. There are alpha and beta directories on the Desktop, and alpha holds several tgz-files.