If you feel that you have to give the correct destination filename, which I don't think you should need to do, then use your filename globbing pattern (which is not a regular expression) in a loop:
for pathname in /my/path/for/the/image/image-abc-*.bin
do
[ -e "$pathname" ] &&
scp "$pathname" "mydevice:flash:$(basename "$pathname")"
done
This would copy all files whose names matches the given globbing pattern. The -e
test makes sure that the pathname in $pathname
actually exists before calling scp
(the pattern would remain unexpanded if there was no matching names found).
The basename
utility is used here to extract the filename portion of the pathname. This is then used as the destination filename. One could also use the parameter substitution "${pathname##*/}"
in place of the command substitution calling basename
.
If you're certain that your pattern would only match a single file, you could also do
set -- /my/path/for/the/image/image-abc-*.bin
[ -e "$1" ] && scp "$1" "mydevice:flash:$(basename "$1")"
This is essentially the same thing as only running the first iteration of the above loop, using the positional parameters to hold the expanded list of pathnames matching the pattern.
mydevice:flash:
.scp
will work fine if the destination is an existing directory, you don't need to give the filename if you want to keep the old one. Btw, this is not regex but globbing. – pLumo Nov 13 '20 at 11:46flash
is the file system I guess, without which copy doesn't work. Even i expected it to work without mentioning the file name in the destination. But not sure, unless I mention the destination file name scp doesn't work – Darshan L Nov 13 '20 at 11:48