I know these questions might have been asked somewhere but their solutions don't really work. I need help.
I want to add a variable to a directory name then change directory to it. The approach below did not work for me.
#!/bin/bash
targetVmwareVersion="15.5.6"
cd vmware-host-modules-workstation-$targetVmwareVersion
If I replace cd
with ls
, it lists contents of the folder on the terminal but the cd
does not work.
I want the targetVmwareVersion
to be concatenated after the name vmware-host-modules-workstation-
then change directory.
I have tried the approach below but it didn't work.
#!/bin/bash
targetVmwareVersion="15.5.6"
path="vmware-host-modules-workstation-$targetVmwareVersion"
cd $path
The cd
part does not work. The directory does not change.
. ./script
does not work for me. The snippet above is part of my large script which depends on that snippet to proceed.
. scriptname
is also an option. – Artem S. Tashkinov Aug 19 '20 at 18:45vmware-host-modules-workstation...
directory in your current directory when you run. ./script
? Do any errors get reported? – Jeff Schaller Aug 19 '20 at 23:02vmware-host-modules-workstation-15.5.6
as a subdirectory and then execute. ./script
, my current directory is changed tovmware-host-modules-workstation-15.5.6
. I would caution you to avoid a variable named "path" (because it's close to "PATH") but your environment has something else that's interfering. – Jeff Schaller Aug 20 '20 at 12:44cd
is built-in, it succeeded anyway, so I'm stumped. – Jeff Schaller Aug 20 '20 at 12:59PATH
after that. – ilkkachu Aug 20 '20 at 15:05cd
command would silently fail. Can you please expand on "does not work" -- in your question? No errors at all? Perhaps you can wrap your tests (before and after) withpwd
. – Jeff Schaller Aug 20 '20 at 16:54cd
just to check if the folder exists or is been seeing and the ls command listed the contents of that folder. My problem was, I wanted thatcd
command to switch the directory on terminal and do something within that folder. Thecd
command did not change directory. I don't know if it opened a sub-shell. I'm not sure. – David Kariuki Aug 20 '20 at 17:40