NOTE: Solution offered below tested and known to work correctly.
Single quotes will break variable expansion if you've aliased part of the path that you're globbing.
Here's a script that uses DOUBLE quotes for the use-case of the globbed filename command-configure_.tar.gz* using a path aliased with a variable:
#!/bin/bash
USEREXECUTINGSCRIPT='admin'
SCRIPTSDIR="myscripts"
SCPUSER='terrencehoulahan'
SCPUSERPASSWD='Change-Me'
SCPHOST='1.2.3.4'
SCPDIRECTORYREMOTE='/Users/terrencehoulahan/Downloads/Ubuntu/18.04'
## Uncomment appropriate below command for your distro to install "sshpass"
#apt-get -y sshpass
#yum -y install sshpass
sshpass -p "$SCPUSERPASSWD" scp -o StrictHostKeyChecking=no $SCPUSER@$SCPHOST:"$SCPDIRECTORYREMOTE/command-configure_*.tar.gz" $(getent passwd|grep ^$(echo $USEREXECUTINGSCRIPT)|cut -d ':' -f6)/$SCRIPTSDIR/
After the closing double quote, the local directory target is constructed by just extracting the specified user's home dir from /etc/passwd.
The scp command itself is prefaced with sshpass
and -o StrictHostKeyChecking=no
to fully automate the scp
command without user interaction. Looks convoluted but better than hard-coding paths which are expected to change from time to time.
Anyhoo, an example using double quotes where variables in the path you're globbing need to be allowed to expand. HTH
*
for file globbing, or to copy a file called*
(see disagreement in comments as to what the question is asking)."C:/test"
— so, the problem is on the local side, which is Windows????? Why is this question on Unix&Linux?rsync
for complicated case like this instead of using scp.