Here is the problem. I have a bash script which getting the path from php script. But it can't change directory to returning path;
function go_to_path
{
path=$(php myscript)
echo $path; # is totally okay, printing expected value
cd $path; # err -> no such file or directory. Directory is obviously exists
}
that stuff does not work too
eval cd $path
echo $(cd $path)
cd "$path"
I am running bash via cygwin on windows
To change directories, use the command cd followed by the name of the directory (e.g. cd downloads ). Then, you can print your current working directory again to check the new path.
This worked fine for me:
function go_to_path
{
path="/home/arnon/scripts"
echo $path
cd $path
}
ls
go_to_path
ls
It won't work if 'path' contains '~' (for instance on this example: path="~/scripts"
) cause that's a shell interpreted character, and not really part of the directory's name.
It also won't work if 'path' is relative to a directory that is not the directory you're running this script from. (In other words if 'php myscript' is returning a relative path make sure the relativity applies to the location your bash script is run from).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With