Possible Duplicate:
Unix “find” command usage
This is for a bash installation script. The script foo.sh takes "DIRECTORY" as an argument. Say, there is a dir /TEST/TEST_1A/TEST_2A/TEST_3 and another dir /TEST/TEST_1B/TEST_2B/TEST_3.
Script: foo.sh in brief.
DIR=`find $HOME -type d -name $1 | head 1'
if [ DIR is set to a directory ]
then
rm -rf $DIR
Usage: foo.sh TEST_3
Now from the script, only the /TEST/TEST_1A/TEST_2A/TEST_3 can be removed. To remove /TEST/TEST_1B/TEST_2B/TEST_3, I need to use a reg exp in my find command, to fine tune the remove to resolve the directory conflict.
Modified the find part of the above script as below
DIR='find $HOME -type d -regexp $1 | head 1
NEW Usage: foo.sh TEST_2B/TEST_3
But "find" command FAILS to get the DIR set to /TEST/TEST_1B/TEST_2B/TEST_3 and instead returns empty & as a result DIR is empty and I can never ever remove /TEST/TEST_1B/TEST_2B/TEST_3
How do I change the script, so that find can act on JUST the directory name, as well as on the path to the directory too with NO issues. Infact, some users may give a partial directory path as argument to "foo.sh". I expect "foo.sh" to work, even in such cases
`
and'
characters. Is that only in your posting here? Or are your scripts trying to use'
in place of`
characters? – sarnold Oct 27 '11 at 23:03head(1)
command actually does? – sarnold Oct 27 '11 at 23:05