0

It works fine when I wrote this code on bash shell

mv -v `pwd`/!(.git) `pwd`/NewDir

But if I create shell script file like below,(name of this file is "s.sh")

#!/bin/bash
mv -v `pwd`/!(.git) `pwd`/NewDir

it returns error

./s.sh: line 2: syntax error near unexpected token `('
./s.sh: line 2: `mv -v `pwd`/(!.git) `pwd`/NewDir'

How can I fix it?

Jeong Ho Nam
  • 803
  • 12
  • 20

1 Answers1

1

!(.git) is an extended glob, you need to enable extglob to make it work in a non-interactive shell. And I think instead of calling pwd twice, you can use PWD variable in this case.

shopt -s extglob
mv -v "$PWD"/!(.git) "$PWD/NewDir"
oguz ismail
  • 1
  • 16
  • 47
  • 69