Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos md5sum末尾的奇怪符号_Macos_Unix_Timestamp_Uuid_Md5sum - Fatal编程技术网

Macos md5sum末尾的奇怪符号

Macos md5sum末尾的奇怪符号,macos,unix,timestamp,uuid,md5sum,Macos,Unix,Timestamp,Uuid,Md5sum,我已在MacOSX上安装了md5sum,其中包括: brew install md5sha1sum 当我试图在终端上创建散列时: timestamp=$(date +%m%d%Y%H%M%S) UUID="$(echo -n "$timestamp" | md5sum )" echo $UUID 散列的末尾有一些奇怪的-符号: [out]: 20e220c825391b96359a7093c33e9f18 - 为什么会这样?如何去除字符串尾随符号? 我可以这样做: timestamp=$(

我已在MacOSX上安装了
md5sum
,其中包括:

brew install md5sha1sum
当我试图在终端上创建散列时:

timestamp=$(date +%m%d%Y%H%M%S)
UUID="$(echo -n "$timestamp" | md5sum )"
echo $UUID
散列的末尾有一些奇怪的
-
符号:

[out]:

20e220c825391b96359a7093c33e9f18 -
为什么会这样?如何去除字符串尾随符号?

我可以这样做:

timestamp=$(date +%m%d%Y%H%M%S)
UUID="$(echo "$timestamp" | md5sum | cut -d' ' -f1)"
echo $UUID

但是,后处理字符串是消除奇怪符号的唯一方法吗?

当您使用
md5sum
从stdin(标准in)计算MD5哈希时,它会输出
-
作为文件名。比如说,

$ md5sum hello.c
ff585184df1b2b93e8e67058e1e708c4  hello.c
$ md5sum < hello.c
ff585184df1b2b93e8e67058e1e708c4  -
或者,根据你的具体情况

UUID="$(echo -n "$timestamp" | md5sum | awk '{print $1}')"
或者


当您使用
md5sum
从stdin(标准in)计算MD5哈希时,它输出
-
作为文件名。比如说,

$ md5sum hello.c
ff585184df1b2b93e8e67058e1e708c4  hello.c
$ md5sum < hello.c
ff585184df1b2b93e8e67058e1e708c4  -
或者,根据你的具体情况

UUID="$(echo -n "$timestamp" | md5sum | awk '{print $1}')"
或者


在UNIX中,
-
通常是一个占位符文件名,表示“标准输入”或“标准输出”。在本例中,它表示标准输入,因为您将数据传输到md5sum。

在UNIX领域,
-
通常是一个占位符文件名,表示“标准输入”或“标准输出”。在这种情况下,它意味着标准输入,因为您将数据传输到md5sum。

而不是回显结果,可以使用
printf
并设置最大长度:

printf "%.32s\n" "$UUID"

由于
md5
始终为32个字符长,因此使用格式字符串应该可以工作。

可能使用
printf
而不是回显结果,并设置最大长度:

printf "%.32s\n" "$UUID"

既然
md5
总是32个字符长,那么使用格式字符串应该是可行的。

为什么需要
md5sum
,为什么不使用内置的
md5
实用程序?因为脚本将在linux机器上运行=)为什么需要
md5sum
,为什么不使用内置的
md5
实用程序呢?因为脚本最终将在linux机器上运行=)