0

I have structure like A directory dir_a/dir_b and dir_c/dir_d to dir_z or some other 100 names.

now I need to copy dir_b into dir_d and all other sub-directories in dir_c. And a part from that every-time I need to copy dir_b into dir_c sub directories it should prompt me confirmation with you want to copy dir_b into dir_d [Y/N]

1

Just loop over the target directories. Use read to ask the user, I added another loop to only get y or n.

#! /bin/bash
for target in dir_c/dir_{d..z} ; do

    answer=''
    until [[ $answer == [YyNn] ]] ; do
        read -p "Copy dir_a/dir_b into $target? (y/n) " answer
    done

    if [[ $answer == [Yy] ]] ; then
        cp -r dir_a/dir_b "$target"
    fi
done
  • No , my friend that structure I gave for example. So to clarify I mentioned more directories . I am still thinking how to get there – rɑːdʒɑ Mar 5 '16 at 19:47
  • @Raja: Without knowing the pattern, it's hard to tell you more. Maybe just dir_c/*? – choroba Mar 5 '16 at 19:59
  • Your answer helped me half. Thank you. I will try dir_c* as well and let you know. – rɑːdʒɑ Mar 5 '16 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.