在 Windows 8.1 上的管理员模式 PowerShell 中运行以下命令会产生奇怪的输出:
PS C:\> cat C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
上面是hosts文件的初始内容。
PS C:\> echo "127.0.0.1 example.com" >> C:\Windows\System32\drivers\etc\hosts
我使用 echo 命令添加一行并...
PS C:\> cat C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
1 2 7 . 0 . 0 . 1 e x a m p l e . c o m
PS C:\>
注意最后一行;它在回显的每个字符之间都有空格。
知道为什么会这样吗?
最佳答案
似乎显而易见的解决方案是不使用 echo "text">> file
格式。尝试使用添加内容:
Add-Content -Path C:\windows\System32\drivers\etc\hosts. -Value "127.0.0.1 example.com"
这将为您提供所需的输出。
关于windows - 为什么回显到 Windows PowerShell 中的主机文件会在字符之间创建空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673026/