0

I am just 6 months old in shell scripting. I am trying to move all directories from one location to another except one in my script When I execute the move command as below it works

mv -vt dir2/ dir1/!(donotmove)

but when I do it like this it fails

des="dir2/"
src="dir1/"
mv -vt $des $src"!(donotmove)"

As my source and destination directories will continuously change I have to use variables. I have tried various combinations but no success

Also executed before executing the above commands

shopt -s extglob

Please let me know where I am making mistake.

  • 2
    Welcome to StackOverflow! Note that `mv` is not a bash command, it's something that comes with your operating system, whatever that is. `man mv` to see its usage, perhaps with examples. Create an [MCVE](https://stackoverflow.com/help/mcve) that we can use to replicate the issue you're seeing. Mention your operating system in the question -- it's important. (On all the systems I use, the `mv` command does not have a `-t` option.) Note that you can always determine whether a command is "built in" to bash with the `type` command. Try `type mv` to see. Compare it to, say, `type test`. – ghoti Dec 12 '17 at 06:06
  • 1
    Did you try `mv -vt "$des" "$src"!(donotmove)`? extglob won't trigger if you enclose the ! expression inside double quotes. – codeforester Dec 12 '17 at 06:13
  • thank you all for your quick replies. – Aashish Dabral Dec 12 '17 at 06:20
  • ghoti: mv works I have been using it extensively. – Aashish Dabral Dec 12 '17 at 06:21
  • codeforester: mv -vt "$des" "$src"!(donotmove) does not work. it gives mv: cannot stat 'dir2/!(donotmove)' : No such file or directory – Aashish Dabral Dec 12 '17 at 06:24

0 Answers0