$ echo *
a b c
$ cat *
file 1
file 2
file 3
$ factor -e=" \
> USING: globs io sequences sorting io.files io.encodings.utf8 ; \
> \"*\" glob natural-sort [ utf8 file-lines ] map concat [ print ] each "
file 1
file 2
file 3
使用Factor的glob和shell的glob输出相同。输出上的diff
表示它们完全匹配。
$ factor -e=" \
> USING: math.parser checksums checksums.sha globs io sequences sorting io.files io.encodings.utf8 ; \
> \"*\" glob natural-sort [ utf8 file-lines ] map concat sha-224 checksum-lines bytes>hex-string print "
0feaf7d5c46b802404760778091ed1312ba82d4206b9f93c35570a1a
$ cat * | sha224sum
d1240479399e5a37f8e62e2935a7ac4b9352e41d6274067b27a36101
但校验和不匹配,也不会md5
校验和。为什么是这样?如何在因子中获得与coreutils sha224sum
相同的校验和?
将编码更改为ascii
不会更改输出,"\n" join sha-224 checksum-bytes
也不会更改checksum-lines
。
答案 0 :(得分:2)
这种奇怪的行为是由于校验和行中的错误造成的。 factor/factor#1708
感谢jonenst找到问题,并感谢您在因子邮件列表中找到此代码的calsioro:
此代码:
[ { "a" "b" "c" } 3 [1,b] [ number>string "file " prepend [ write ] curry ascii swap with-file-writer ] 2each "*" glob natural-sort [ utf8 file-lines ] map concat [ "\n" append ] map "" join ! Add newlines between and at the end sha-224 checksum-bytes bytes>hex-string print ] with-test-directory
给出相同的哈希:
d1240479399e5a37f8e62e2935a7ac4b9352e41d6274067b27a36101
答案 1 :(得分:0)
此外,关于你获得的三种不同长度,“exercism / self-update / self-update.factor”在最后一行的末尾缺少'\ n'字符。这就是为什么你会得到令人惊讶的结果。
如果您正在尝试校验和文件,请确保它们都以尾随换行结束。