cd command doesn't work through variables

Hi....
cd command is not working when dual string drive/volume name is passed to cd through variables.......
For Ex....
y=/Volumes/Backup\ vipin/
cd $y

the above command gives error.......
anyone with a genuine solution ?

try:
make sure the PATH is correct. The shell has to evaluate the value of y first before it cn cd.

cd ${y}

cheers,
Devaraj Takhellambam

it doens't work in case of dual word volume name........
that space between the two word is the culprit.....

even though the shell evaluate the value of variable correctly still cd doesnt work ,gives error because of the space between two words

What is the actual directory path? Can you do a direct CD to the PATH?

yes the actually cd to the path is possible but it doesn't work when the value is passed through a variable........
for Ex....
cd '/Volumes/Backup vipin/' is working
But
y=''/Volumes/Backup vipin/'"
echo $y
'/Volumes/Backup vipin/'
cd $y
-sh: cd: '/Volumes/Backup: No such file or directory

doesn't work...

I am also new to shell scripting can you tell me ..
why are you using "\" in /Volumes/Backup\ vipin/

Now I understand what you are trying to do ..put it in the quotes as there is a space.

y='/Volumes/Backup vipin'
cd "${y}"

cheers,
Devaraj Takhellambam

"\" is used because the next special charactor after "\" can be considered as a normal charactor and a part of the string

try this....

y="/Volumes/Backup\ vipin/"
cd "$y"

your idea doesn't work.here is the error message.......
-sh: cd: /Volumes/Backup\ vipin/: No such file or directory

your idea doesn't work.here is the error message.......
-sh: cd: /Volumes/Backup\ vipin/: No such file or directory

try dropping the escaping slash.....

y="/Volumes/Backup vipin/"
cd "$y"

Did you try this

y='/Volumes/Backup vipin'
cd "${y}"

cheers,
Devaraj Takhellambam

BTW, which shell are you using???

it can / will act differently in each shell.

ya it works............
nice grey matter......

Good. The quotes are confusing at times. So the codes are put into the grey code section for easier visibility.

cheers,
Devaraj Takhellambam