我正在运行一个脚本,我希望它能够打印一个"语句+变量+语句"最后[成功时]。我尝试过一些东西,但它总是以三条独立的线条而不是一条线条返回。回声""之前和之后只是为了让它在打印时更容易阅读,我已经尝试过,我得到了相同的结果。
$filename = "foo.csv"
echo ""
echo "The file" $filename "has been processed."
echo ""
我明白了:
The file
foo.csv
has been processed.
答案 0 :(得分:14)
如果你使用双引号,你可以直接在字符串中引用变量,因为它们允许变量扩展,而单引号不允许这样做。
$filename = "foo.csv"
Write-Output "The file $filename has been processed."
-> The file foo.csv has been processed.
另外,echo
实际上只是Write-Output
的别名,所以我使用了全名。
答案 1 :(得分:5)
在powershell中,您可以按如下方式使用Write-Host:
$filename = "foo.csv"
Write-Host 'The file' $filename 'has been processed.'
-> The file foo.csv has been processed.
答案 2 :(得分:0)
echo ("The file "+ $filename +" has been processed.")