in you locateRoot
function you just echo
only root
not content of it, which is wrong and your script seems to very lengthy to perform some simple task.i give you sample script which print path to directory which contain text.txt
file.
#! /bin/bash
locateRoot ()
{
var=$(find / -iname "text.txt" -printf '%h\n' | sort -u)
printf "%s \n" "$var"
}
you can see absolute path to that directory which contain that file. You can modify above script to perform certain task as you want by just cd
to that directory like
cd $var
//execute your command in $var directory