Powershell Cygwin 使用 Rsync 遠端複製資料作為變數

Powershell Cygwin 使用 Rsync 遠端複製資料作為變數

我對 Cygwine 的 rsync 有問題。使用 Powershell 腳本,我嘗試將目錄從 Novell 伺服器傳輸到 Windows 伺服器

來源的路徑是來自 CSV 檔案的變數

Function CopyRsync ([string]$source,[string]$dest){   
        $sourceRoot = "root@"+$source +"/"        
        $dest = "/cygdrive/g/Shares/" +$dest

cmd.exe /C "e:\cwRsync\bin\rsync.exe" -vrts --progress --whole-file --no-compress --no-checksum  -e "/cygdrive/e/CWrsync/bin/ssh" $sourceRoot $dest --delete-before         
    }

$novel = 'server.domaine.local:/media/nss/rep01/Com/Com dir Soins info'
$dfs = "C:\temp\Rsync"
CopyRsync -source $novel -dest $dfs

如果變數中的來源路徑不包含空格,則腳本正確運行,但如果路徑包含空格,則變數的內容將用引號解析,並且腳本停止運行,因為 SSH 會話收到「root@.txt」。用戶,在用戶root 的開頭加上引號,如下所示

"E:\cwRsync\bin\rsync.exe" -vrts --progress --whole-file --no-compress --no-checksum -e /cygdrive/e/CWrsync/bin/ssh "[email protected]:/media/nss/rep01/Com/Com dir Soins info/" /cygdrive/g/Shares/C:\temp\Rsync --delete-before

如何解析變數以忽略腳本變數的引用?

答案1

我使用 Visual Studio Code,程式碼運行良好。我認為 Powershell 的 ISE IDE 無法正確解釋引號

相關內容