如何使用Bash写入二进制文件? [英] How to write a binary file using Bash?

查看:307
本文介绍了如何使用Bash写入二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我需要创建一个具有以下确切字节的文件:48, 00, 49, 00.

My problem is that I need to create a file with this exact bytes: 48, 00, 49, 00.

我不能使用C,perl,其他脚本语言(目标是嵌入式设备).我使用awk尝试了此操作,并且在桌面上确实可以工作:

I cannot use C, perl, other scripting language (the target is an embedded device). I tried this using awk, and in desktop it does work:

# awk  'BEGIN{ printf "%c%c%c%c", 48, 00, 49, 00 }' | hexdump
0000000 0030 0031                              
0000004

但是,目标平台正在运行busybox v1.13.2,并且此代码在此处不起作用.在那里的awk版本不会输出ascii"0"(其他所有值都可以).

However the target platform is running busybox v1.13.2 and this code does not work there. The awk version there does not output ascii "0" (all other values are ok).

您有什么建议?

推荐答案

您可以使用以下命令:

echo -n -e \\x48\\x00\\x49\\x00 > myfile

这篇关于如何使用Bash写入二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆