I want to know how can I copy or shell copy multiple files within a bash script. What I mean is that
cp /path/to/source/{file1,file2,file3} /path/to/dest
and
scp /path/to/source/{file1,file2,file3} user@host:/path/to/dest
will work fine but as example
#!/bin/sh
scp /path/to/source/{file1,file2,file3} user@host:/path/to/dest
will throw an error like this:
/path/to/source/{file1,file2,file3}: No such file or directory
If you will copy or shell copy a single file it works, so the problem are multiple files. Also it works if I would use *
for all files but I do not want to copy all files. I should only copy selected files because in both folders are files with the same name but their content is different. Thereby to copy all files and then remove the not needed files would not work.
For better understanding following would work:
#!/bin/sh
scp /path/to/source/file1 user@host:/path/to/dest
Also following:
#!/bin/sh
scp /path/to/source/* user@host:/path/to/dest
So it has something to do with the correct use of { ... }
for multiple files which will work inside the terminal but not if I run the bash script in it.
Thanks in advance.
//Edit:
I add the error if I try it with cp:
cp: cannot stat '/path/to/source/{file1,file2,file3}': No such file or directory
ls -l /bin/sh
? – BlueManCZ Feb 23 '21 at 10:55bash script.sh
instead of./script.sh
? – BlueManCZ Feb 23 '21 at 10:59lrwxrwxrwx 1 root root 4 Apr 23 2020 /bin/sh -> dash
. If I run it withbash script.sh
instead of./script.sh
it does not change anything. I will get the same errors. But a good point you raised there. – Micha93 Feb 23 '21 at 11:01{}
are output in the error message, only he does not perform it accordingly. I feel extremely stupid because I am missing some very simple trivial part. I'm really doubting myself right now. – Micha93 Feb 23 '21 at 11:04dash script.sh
. Once more, what is the output ofls -l /bin/bash
? – BlueManCZ Feb 23 '21 at 11:09bash --version
? – BlueManCZ Feb 23 '21 at 11:10-rwxr-xr-x 1 root root 1113504 Jun 7 2019 /bin/bash
and `GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.htmlThis is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.`
– Micha93 Feb 23 '21 at 11:11