Search code examples
bashpathcygwincd

change directory from string


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


Solution

  • ohh my. So I guess I haven't compose my question correctly. The path value is taken from dynamic algorithm. Which just echo returning value. The solution was easy, instead of echoing value I should exit it. I mean exit the script with path value.