This is for a bash installation script. The script foo.sh takes \"DIRECTORY\" as an argument. Say, there is a dir <$HOME>/TEST/TEST_1A/TEST_2A/TEST_3
and anot
Wouldn't this work as intended?
find $HOME -type d -name $1 -exec echo {} ';' -exec rm -rf {} ';'
It will complain about deleting of processed directory, but toher than some stderr output it's ok...
You can ofc change "-name" for "-regexp" as you suggested, but if you want something more complex, you can create special script to call from "-exec"
EDIT: I probably understood you wrong first time (but won't delete anything, it may help somebody) - you want to delete only one of TEST_3 directories (how do you choose which one? first found by find? - it seems quite strange), still as I suggested in previous paragraph, you can provide skript to -exec which will take care of all decision making)
You could try:
if [[ "$1" == */* ]]; then
EXPR="-path *$1"
else
EXPR="-name $1"
fi
DIR=$(find $HOME -type d $EXPR | head -1)
A simple name like "TEST_3" will translate into find -name TEST_3
but a name with a slash like "ST_2/TEST_3" will translate into find -path *ST_2/TEST3
. This will take care of (partial) directory names.