(Un / De)在bash中压缩字符串? [英] (Un/De)compress a string in bash?

查看:82
本文介绍了(Un / De)在bash中压缩字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用stdin / stdout对bash中的字符串进行压缩/解压缩?

Is it possible to compress/decompress a string in bash using stdin/stdout ?

我尝试了此操作,但显然不支持此操作?

I tried this but apparently it is not supported ?

hey=$(echo "hello world" | gzip -cf)
echo $hey # returns a compressed string
echo $hey | gzip -cfd
gzip: stdin is a multi-part gzip file -- not supported

我不太精通linux,但是我阅读了其他压缩实用程序的手册页,却找不到解决方案?

I'm not well versed in linux but I read other compression utilities man pages and couldn't find a solution?

推荐答案

何时您可以这样做:

hey=$(echo "hello world" | gzip -cf)

变量中的字节数与 / tmp / myfile 创建者:

You don't have same same bytes in variable hey as you have in /tmp/myfile created by:

echo "hello world" | gzip -cf > /tmp/myfile

您会收到 gzip:stdin是多部分gzip文件-不支持错误只是因为您破坏了无法解压缩的压缩数据。

You get "gzip: stdin is a multi-part gzip file -- not supported" error simply because you have broken compressed data which cannot be uncompressed.

VAR = $(...)结构是为处理文本而设计的。这就是为什么您需要额外的尾随修剪的原因。

The VAR=$(...) construction is designed for working with text. This is why you get extra trailing trim for example.

这篇关于(Un / De)在bash中压缩字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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