Copy all files except…
Comments: 0 - Date: August 29th, 2007 - Categories: Quick Tips, Shell Scripts, OS X, Linux
Here’s a problem I just came across. I needed a shell script, make_backup, used to copy all of the files in the directory in which the script is located to a backup directory without copying the make_backup shell script itself. I searched online to find the easiest way to do this, but for some reason, the command wasn’t working. Here’s the bash command:
cp -r !(make_backup) $backup_dir
Every time I attempted to execute the shell script, bash gave me an error stating that the ‘(’ was “unexpected”. Searching around on line was telling me that this was a supported bash command, but obviously, it wasn’t on my machine. After some digging, I came to the realization that you have to enable composite patterns in bash for this to work. To do this, place the following line before the “cp” command (I put it in my .bashrc file so I don’t have this problem again):
shopt -s extglob
That’s it! You should now be able to use the extended globbing commands. Read more about it here: http://www.faqs.org/docs/bashman/bashref_35.html
Leave a comment
You must be logged in to post a comment.
Categories
Recent Posts
Search
Links
Design © 2006 by the undersigned | Theme sponsor: Fresh Flowers Direct (http://www.digitalflowers.com)