I am planning to execute an operation using the backtick operator in a foreach loop. I want to change to the desired directory before the loop, and then iterate without needing to change the directory back.
The following simple test seems to show that you can not stay in the same directory between operations:
$output=`pwd`."<br />";
$output.=`cd ~/domains && pwd`."<br />";
$output.=`pwd`;
echo $output;
die;
// output
home-path
home-path/domains
home-path
Is there a way to accomplish this? Or should I just cd
to the directory every time I execute in the foreach loop?