bash - awk '{printf "%d ", 49420877107}' 打印错误的数字 2147483647

标签 bash shell awk

我在不同的电脑上运行相同的 shell 代码 awk '{printf "%d ", 49420877107}',但是得到不同的答案。


电脑一号
Shell

awk --version
GNU Awk 4.1.3

System Information


PC二
Shell

awk --version 
awk:not an option
awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
compiled limits:
max NF             32767
sprintf buffer      2040

awk '{printf "%d ", 49420877107}'
2147483647

System Information


有人知道原因吗?非常感谢。

最佳答案

第二个显示 2147483647 将 %d 视为 4 字节整数,而第一台 PC 使用更多字节,可能是 long。这将取决于 awk 在该机器上的编译方式或使用的 awk 版本。

checkout :https://superuser.com/questions/646919/how-can-i-find-my-awk-version

关于bash - awk '{printf "%d ", 49420877107}' 打印错误的数字 2147483647,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48577423/

相关文章:

bash - 生成 SAS 以访问 Azure 存储

linux - grep 命令反转选项不起作用

linux - 程序运行后的 UNIX 清除命令

Bash 脚本,执行命令,在每一行前加上给定的字符串

bash - 引用 shell 变量的打印

ubuntu - 如何在 .awk 脚本中编写多个命令?

python - docker-compose exec 导致 [Errno 2] 没有这样的文件或目录 : 'docker-compose' : 'docker-compose' in docker container

linux - Bash shell - 按时间顺序统计并显示目录和子目录列表

awk - 命令行,多行搜索和替换

linux - 用awk解析多行