I want to define the function
cpfromserver in bash so that when I run
$ cpfromserver xxx yyy zzz
the result is the same as if I had typed
$ scp email@example.com:"/some/location/xxx/xxx.txt /some/location/xxx/xxx.pdf /some/location/yyy/yyy.txt /some/location/yyy/yyy.pdf /some/location/zzz/zzz.txt /some/location/zzz/zzz.pdf" /somewhere/else/
where it works for any number of arguments.
(That is, the function should copy
filename.pdf from the directory
/some/location/filename/ on the
remote.server to the local directory
/somewhere/else/ for every
filename I specify as an argument to the function. And do it all in a single
Currently, I have written a function that works for a single argument, and I just loop over it, but this establishes separate
ssh connections for each argument, which is undesirable.
My difficulty is that I only know how to use function arguments individually by their position (
$2, etc.) — not how to manipulate the whole list.
[Note that I am writing this function as a convenience tool for my own use only, and so I would prioritize my own ease of understanding over handling pathological cases like filenames with quotation marks or linebreaks in them and whatnot. I know that the filenames I will be using this with are well-behaved.]