【发布时间】:2020-04-11 07:35:18
【问题描述】:
我在 PowerShell 中得到以下信息:
D:\> echo "Apple Pie" | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053
D:\> "Apple Pie" | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053
但在 CMD.exe 中:
C:\>echo "Apple Pie" | git hash-object --stdin
bb3918d5053fea31fc9a58fae1e5bdeabe3ec647
在 PluralSight 视频中,我看到了与 Mac 控制台不同的价值:
在每种情况下,从echo 传输的确切值是多少?
如果我转到其中一个在线 SHA1 生成器并输入字符串 Apple Pie,我会得到不同的哈希值。从我得到的:
8d69b7365f59237d3fb052c1f2f15ea33457fe51
【问题讨论】:
-
cmd.exe的 内部命令 ECHO 还输出双引号和留给重定向运算符|的空格字符。我想没有测试,因为没有安装git,散列将与PowerShell中使用echo Apple Pie| git hash-object --stdin创建字符串Apple Pie的散列相同。如果它仍然不同于cmd命令,ECHO 还会在字符串Apple Pie之后输出换行符。 -
你是对的!
echo Apple Pie|git hash-object --stdin产生157cb7b..,与 PowerShell 'echo "Apple Pie"` 相同。 -
而 Powershell
echo '"Apple Pie" ' | git hash-object --stdin产生bb39...,与 CMDecho "Apple Pie" | ...相同。 -
echo "Apple Pie" | where {$_length -eq 9}表示该字符串没有添加CRLF,但如果重定向到文件,则有CRLF。
标签: powershell cmd hash sha1 git-hash