传递二进制数据作为在bash参数 [英] Passing binary data as arguments in bash

查看:149
本文介绍了传递二进制数据作为在bash参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要二进制数据传递给接受命令行参数的bash程序。有没有办法做到这一点?

这是一个接受一个参数的程序:

 脚本ARG1

但不是字符串 ARG1 ,我想通过一些字节是不好的ASCII字符 - 特别是字节 0X02 0xc5 0xd8

我如何做到这一点?


解决方案

 脚本`printf的\\ X02 \\ XC5 \\ xd8`
脚本`回声-e\\ X02 \\ XC5 \\ xd8`

测试:

 #回声-n`回声-e\\ X02 \\ XC5 \\ xd8`| hexdump都-C
00000000 02 C5 D8 | ... |

I need to pass binary data to a bash program that accepts command line arguments. Is there a way to do this?

It's a program that accepts one argument:

script arg1

But instead of the string arg1, I'd like to pass some bytes that aren't good ASCII characters - in particular, the bytes 0x02, 0xc5 and 0xd8.

How do I do this?

解决方案

script "`printf "\x02\xc5\xd8"`"
script "`echo -e "\x02\xc5\xd8"`"

test:

# echo -n "`echo -e "\x02\xc5\xd8"`" | hexdump -C
00000000  02 c5 d8                                          |...|

这篇关于传递二进制数据作为在bash参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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