Need Help in going to ~ directory

Hi,
I have a variable "COMPBD=~zzzdba/comps" which i want to read and substitute in my script like cd $COMPBD. But it didnt work like that....Please can somebody throw some light on this....

thanks...
-Prasanna.K

What does "didnt work like that" mean?

What did happen?

What, exactly did you do?

Is there an account named zzzdba?

Did you quote the variable when you used it? If not, it would have failed if there were spaces in the name of the directory.

Which shell are you using?
Assuming there is an account in passwd file called zzzdba, and a directory under the user's home directory called comps, and you have permissions to "cd" to that directory.

This behaviour is a feature of ksh (see man pages). Tilde substitution only works on unquoted strings.
This works:
cd ~myname
This doesn't work:
cd "~myname"

In your case this should work.
COMPBD=~zzzdba/comps
cd ${COMPBD}
You can check the substitution.
echo "${COMPDB}"

If it still doesn't work maybe you need to force ksh (or a shell which supports tilde substitution) on the very first line of your script.
#!/bin/ksh

It is a feature of all standard Unix shells, as well as tcsh (and probably csh, but I don't have a copy to test with).

But if it's a variable, the tilde expansion is done during the assignment, and the variable can, and should be, quoted.

That will fail if there's a space in the directory name. Use:

cd "$COMPBD"

i tried the below..
path=`cat /bridge/profiles/Z1000 | grep 'COMPBD=' | cut -d"=" -f2`
echo $path
~zzzdba/comps

cd $path
ksh: ~zzzdba/comps: not found

cd ${path}
ksh: ~zzzdba/comps: not found

cd "${path}"
ksh: ~zzzdba/comps: not found

Please suggest any idea.....

i tried the below..
path=`cat /bridge/profiles/Z1000 | grep 'COMPBD=' | cut -d"=" -f2`
echo $path
~zzzdba/comps

cd $path
ksh: ~zzzdba/comps: not found

cd ${path}
ksh: ~zzzdba/comps: not found

cd "${path}"
ksh: ~zzzdba/comps: not found

Please suggest any idea.....

UUOC; use the filename as an argument to grep.

Where have you allowed the shell to expand it? Nowhere!

Tilde expansion is not performed on variables.

Use eval:

eval "path=$path"