I'm trying to write a bash script which will copy a bunch of files and directories from a directory, omitting a couple but taking everything else.

I have got a command that does this and works from the command line:

cp -r !(dspace.cfg|README.md) ~/tmp/directory

This does exactly what I want it to do, so I've put it into my bash script (which does some other things besides), so it looks like this:



# copy everything except the readme and the dspace.cfg extension
cp -r !(dspace.cfg|README.md) $SRC/config

And when I run it I get:

$ bash addmodule.sh 
addmodule.sh: line 7: syntax error near unexpected token `('
addmodule.sh: line 7: `cp -r !(dspace.cfg|README.md) $SRC/config'

I've checked all the obvious things: the shebang is right, I'm running it explicitly with bash from the command line (I've checked that on my Ubuntu 14.04 system that this really is bash and not dash), and I've checked that posix is off (though I'm not sure if that would make any difference in this case).

Basically all I want is a script that wraps up a few commands that I'd run from the command line, and that's about the extent of my knowledge!


Browse other questions tagged or ask your own question.