Generalising UNIX file path

There's a Unix configuration file that needs to be executed at the start of my script
The location of the file is

/Dstage/AA_INTERFACES/SYSTEM_FILES/MISC/

Now the script has to be deployed into a new UAT server for testing
where the location above has been change to

/UATServ/Accp/Admin/AA_INTERFACES/SYSTEM_FILES/MISC/

The problem is if I hard code the file location in my script,
the script is usre to abort when migrated onto the new UAT server
BECAUSE in the UAT server , it wouldn't be able to find the location

/Dstage/AA_INTERFACES/SYSTEM_FILES/MISC/

What I was looking for is :
Both these paths have a portion in common,, ie.,

/AA_INTERFACES/SYSTEM_FILES/MISC/

So, isnt there any way that I can access the file
where the path of the file has

/AA_INTERFACES/SYSTEM_FILES/MISC/

in it ?
How to generalise the file path if a portion of it is always common ?

Thanks
Kumarjit.

I believe your model has problems. Yes. we can do that -

/Dstage/AA_INTERFACES/SYSTEM_FILES/MISC/
# becomes
/*/AA_INTERFACES/SYSTEM_FILES/MISC/

But this is a slower lookup than a fully specified path name

/AA_INTERFACES/SYSTEM_FILES/MISC/

Assume the filename of the above is foo.txt:

server=$(uname -a | awk '{print $2}')
if [ $server = "PROD" ] ; then
  export pathname=/Dstage
else
  export pathname=/UATserv
fi

BASE=$(cat foo.txt)
LOCATION=$pathname/$BASE
1 Like

Thanks for the quick response Jim, but
whats the use of the following line in your
code piece ??

BASE=$(cat foo.txt)

Thanks
Kumarjit.

Maybe something like the following:

common_path=AA_INTERFACES/SYSTEM_FILES/MISC/

if [ $HOSTNAME = "kitty" ]; then
  path=/UATServ/Accp/Admin/$common_path
fi

if [ $HOSTNAME = "aardvark" ]; then
  path=/Dstage/$common_path
fi