I have following variables
$a=/opt
$b=var
$c=usr
$path=/$a/$b/$c/man
when I do cd $path it says no such file or directory.
but this path actually exist /opt/var/usr/man .. any suggestion ?
The problem is a bad syntax in variable assignments.
$a=/opt
$b=var
$c=usr
$path=/$a/$b/$c/man
.. will never work since variable assignments must not be preceded by $
.
You should instead do it as follows:
a=opt
b=var
c=usr
dir=/$a/$b/$c/man
cd $dir
Note that I changed the final variable name as it is a bad idea to use two variables with the same name but in a different case as it can be confusing. (PATH
being a very important environment variable)
If you try this echo $a$b$c
you will get this
[root@centseven ~]# echo $a$b$c
/optvarusr
So this is not a a execute.
Your last variable should be path=/$a$b$c/man
Change your variable to the below
$a=/opt
$b=/var
$c=/usr
Then try echo $path
it works for me
[root@centseven ~]# echo $path
/opt/var/usr/man
echo $path
he is trying cd $path
.
echo $path
can not fail so if you say it didn't work, you have to say what it did.
ls -ld /opt/var/usr/man
?
echo $path
. because you don't have / mentioned in the variable. its not working.echo $a$b$c
$path=/$a/$b/$c/man
doesn't do what you think it does. Trypath=test;$path=123
and see what error message it prints. 2. Why aren't you quoting your parameter expansions?PATH
or$PATH
. I used lower-case$path
in my example because that's what the OP used.