1

Im trying to move all the contents of the current directory to a new folder in the current directory using a script

mv !\(.svn\|$line\|.\|..\) $line

error is

mv: cannot stat '!(.svn|RSSIFXServicesCommon|.|..)': No such file or directory

I echoed the command to output and if i copy and execute the command myself, it works.

I tried enabling extglob

venky
  • 73
  • 12
  • Possible duplicate of [Move all files except one](https://stackoverflow.com/questions/670460/move-all-files-except-one) – mabi Jan 22 '18 at 18:34

1 Answers1

1

With extended regex (shopt -s extglob), there's no need to quote your regex:

mkdir -p /tmp/t/4
touch /tmp/t/{1,2,3}
shopt -s extglob
cd /tmp/t
mv !(4|.|..) 4

This also works if I put this in a shell script.

mabi
  • 5,279
  • 2
  • 43
  • 78
  • `mv: cannot stat '!(4|.|..)': No such file or directory` – venky Jan 22 '18 at 18:50
  • Which shell is that? – mabi Jan 22 '18 at 19:13
  • its bash but its running on a MingW64 – venky Jan 22 '18 at 19:33
  • That doesn't sound like the bash version(s) I've around here. If extglob doesn't work, bash should interpret the '!' as history expansion and you should get an [event not found](https://serverfault.com/questions/208265/what-is-bash-event-not-found) message (unless your bash even has history expansion disabled?). – mabi Jan 22 '18 at 21:39
  • if the extglob is unset, it is interpreting the "!" as previous event just like you said. But i have set the extglob and when I run the command `mv !(4|.|..) 4` it is giving the following error `mv: cannot stat '!(4|.|..)': No such file or directory` – venky Jan 23 '18 at 15:41