[英]Getting md5sum hash from awk script
在我的Linux Shell(ubuntu)上,如果输入以下命令:
echo -n -e "THIS IS A TEST" | md5sum
我得到的md5哈希值为:1586CFFAFA39E38959477DA9EAA41C31
如果我执行以下操作:
awk -f short.awk
其中short.awk包含:
BEGIN {
print "HELLO"
md5sum_command = sprintf("echo -n -e \"%s\" | md5sum", "THIS IS A TEST");
if ( (md5sum_command | getline line) > 0) {
result = line;
type = "linux";
hash_command = "echo -n -e \"%s\" | md5sum";
printf("Command: %s\nResult = %s\n", md5sum_command, result);
printf("It looks like you are on a linux environment, so the md5sum command will be used\n");
} else {
result = "FAILED";
}
close(md5sum_command);
}
我得到的md5哈希值是:a842e5b39bf5aef1af5d4a0ef7acf8e9
我不知道是什么问题。
您正在运行echo
两个不同版本。 通过awk运行时,您可以从交互式shell中的/bin/bash
获取内置函数,而从/bin/sh
获取内置函数。 他们的行为有所不同。
在两种情况下,使用/bin/echo
可获得一致的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.