Fix console working directory for root user (#525)

Previously, `$(pwd)` was expanded too early by the parent shell, leading to incorrect working directory output when `cd` was executed within `$request->command`. Replaced `echo "VITO_WORKING_DIR: $(pwd)"` with `echo -n "VITO_WORKING_DIR: " && pwd` to ensure `pwd` executes at the right moment inside the same shell session.

Closes #515
This commit is contained in:
Dimitar Yanakiev 2025-03-02 11:55:06 +02:00 committed by GitHub
parent 97e20206e8
commit 49137a757b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,7 +37,7 @@ public function run(Server $server, Request $request)
return response()->stream(
function () use ($server, $request, $ssh, $log, $currentDir) {
$command = 'cd '.$currentDir.' && '.$request->command.' && echo "VITO_WORKING_DIR: $(pwd)"';
$command = 'cd '.$currentDir.' && '.$request->command.' && echo -n "VITO_WORKING_DIR: " && pwd';
$output = '';
$ssh->exec(command: $command, log: $log, stream: true, streamCallback: function ($out) use (&$output) {
echo preg_replace('/^VITO_WORKING_DIR:.*(\r?\n)?/m', '', $out);