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 Answer 1

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
3
  • No , my friend that structure I gave for example. So to clarify I mentioned more directories . I am still thinking how to get there
    – Raja G
    Mar 5, 2016 at 19:47
  • @Raja: Without knowing the pattern, it's hard to tell you more. Maybe just dir_c/*?
    – choroba
    Mar 5, 2016 at 19:59
  • Your answer helped me half. Thank you. I will try dir_c* as well and let you know.
    – Raja G
    Mar 5, 2016 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .