I created a script using PHP CLI that I would like to have cd me into a directory based upon my command line input.
While I can get the PHP execution commands to echo output (e.g. echo ls -al), I cannot get them to run cd.
I have searched a lot online to find the solution, but have come up empty.
You can’t use
cdas it would run in a subshell, and the changed working directory would be lost when you returned to PHP before issuing the next command.Use
chdirinstead.