代码之家  ›  专栏  ›  技术社区  ›  leeand00

在Windows中的powershell中处理多行内容时,为什么会占用每一行并将其添加到命令历史记录中?

  •  -1
  • leeand00  · 技术社区  · 6 年前

    我开始使用 pwsh 在Linux中,使用它是一种乐趣。然而,回到Windows,它仍然很难使用 powershell.exe 主要是因为当你将文本粘贴到powershell窗口时,它会使粘贴的每一行代码都成为命令历史记录的一个条目!

    在里面 pwsh 它使你粘贴的所有内容成为命令历史记录中的一个条目。。。

    微软如何能比Windows用户更好地照顾Linux用户,或者这是一个奇怪的安全问题?原因是什么?

    使用Ubuntu 16.04 LTS和Windows Server 2016

    0 回复  |  直到 6 年前
        1
  •  0
  •   AdminOfThings    6 年前

    情况并非总是如此。如果你想要这种效果,有几种方法可以制作:

    PS H:\> $str = "this is line 1
    >> this is line 2
    >> this is line 3"
    PS H:\>
    PS H:\> $str
    this is line 1
    this is line 2
    this is line 3
    PS H:\>
    PS H:\> & {$str
    >> $str
    >> $str}
    this is line 1
    this is line 2
    this is line 3
    this is line 1
    this is line 2
    this is line 3
    this is line 1
    this is line 2
    this is line 3
    PS H:\> history
    
      Id CommandLine
      -- -----------
       1 $str = "this is line 1...
       2 $str
       3 & {$str...
    
    
    PS H:\>
    
    推荐文章