I read that I must put the command
shopt -s extglob
in .bashrc
in order to use !(XYZ)
as a wild card expansion for everything in the current directory except XYZ. Testing indicated that
cp -aruv !(XYZ) $target
indeed copied everything from the current directory to $target except sub directory XYZ. Then I included the cp statement in a bash script. The script died at the cp statement with error message
cp: invalid option --'h'
which I cannot explain. I added the shopt command to my script and got the same result.
I found this wild card expansion in "Your UNIX" by Das with the comment to add the shopt statement to .bashrc. I do not find shopt
in either man or info.
Any help would be appreciated to get the correct wild card expansion in a bash script statement and on where to find information on the shopt command.
There have been questions about my script that I tried to answer but did so in the wrong place. There are portions of the script.
#!/bin/bash
if shopt -s extglob
then
echo "shopt was successful"
else
echo "shopt was not successful"
exit -1
fi
Following these statements is a loop in which target and source are set and tested to insure that they point to directories. Then the code that fails
cd $source
cp -aruv !(XYZ) $target
Again I point out that if I set target and source from the command line and then
cd $source
cp -aruv !(XYZ) $target
the copy works as I expect. I can do this other ways but would like to understand why this does not work in my script and how to fix it.