0

I need to copy the content of the parent directory to the newly created sub-directory.

Initially, the structure is like this:

Parent
    abc.txt
    work_dir/
        script.sh

Expected Output:

Parent
    abc.txt
    work_dir/
        script.sh
    sub_dir/
        abc.txt
        work_dir/
            script.sh

Now I am in the work_dir, and I am executing script.sh. The content of this file is below:

/bin/sh
mkdir ../sub_dir
shopt -s extglob
cp -r ../!(sub_dir) ../sub_dir/

I get the following error: syntax error near unexpected token `('. Error: exit status 2

If I change it to this cp -r '../!(sub_dir)' ../sub_dir/, I get cp: ../!(sub_dir): No such file or directory

Any help is appreciated, Thanks

disp_name
  • 1,448
  • 2
  • 20
  • 46

1 Answers1

0

rsync solved the issue. See the updated code:

/bin/sh
mkdir ../sub_dir
rsync -a --exclude=../sub_dir ../ ../sub_dir/
disp_name
  • 1,448
  • 2
  • 20
  • 46