I need to run this command in a shell script to copy source > destination and exclude a folder.
No rsync, tar, find, mv, etc.
Exactly this command:
cp -var test/!(test2) testbkp
- In the shell it works
- Run from a Bash script without exclude like
cp -var test testbkpit works.
When I try to run from a Bash script with the exclude option
cp -var test/!(test2) testbkp, it doesn't work.
There isn't any output, nothing, and no error message.
I checked this post too, but no result: cp command won't run if executed from shell script
How can I run this cp command in a Bash script and exclude folders?
cpis not part of bash -- it's a separate executable (typically something like/usr/bin/cp) you can use without any shell at all; so "bash 'cp' command" is somewhat misleading. On the other hand, it is the shell responsible for taking a glob expression (liketest/!(test2)) and generating a list of filenames from that expression before thecpexecutable (or whatever other executable you run) is started.