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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

mv: cannot stat '!(4|.|..)': No such file or directory
Which shell is that?
its bash but its running on a MingW64
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 message (unless your bash even has history expansion disabled?).
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.