Powershell此处字符串扩展

弦乐

关于Powershell“ here-string”有一些示例,但是我几乎没有遇到过“ here-string”扩展。所以我发布了一些帮助。

当您想添加带有换行符的文字时,单引号和双引号都不需要转义,也不需要换行符"`r`n"在PowerShell中可以使用“ here-strings”。他们应该从

@”
和换行符,应以换行符
“ @”结尾

For example:                        |Result:
                                    |
@"                                  |
Hello world! 09/25/2014 11:39:56    |      Hello world! 09/25/2014 11:39:56
'(this will appear as is)'          |      '(this will appear as is)'
!                                   |      !
"@                                  |

这是如何引入CmdLet和日期变量来像这样显示当前日期:
例如,以下是我们要实现的目标:

Hello world! 09/25/2014 11:39:56
'(this will appear as is)'
!

方法如下:

@"
Hello world! $(Get-Date)
'(this will appear as is)'
!
"@

或带有变量:

$myDate = Get-Date
@"
Hello world! ${myDate}
'(this will appear as is)'
!
"@

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章