击弦差异 [英] Bash string difference

查看:122
本文介绍了击弦差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来确定我的剧本两个字符串之间的区别。我可以很容易地做到这一点有差异或通讯,但我不处理文件,我倒是没有preFER将它们输出到文件,执行比较和读取它。

I'm trying to find a way to determine the difference between two strings in my script. I could easily do this with diff or comm, but I'm not dealing with files and I'd prefer not to output them to files, do the compare and read it back.

我看到COMM,差异,CMP都允许通过其中两个文件或文件和标准输入 - 我想这是很好的,如果我不想输出两个文件...但它仍然有点儿吮吸

I see that comm, diff, cmp all allow to pass either two files OR a file and standard input - I guess that's good if I don't want to output two files...but it's still kinda sucks.

被四处想我可以用grep或经常前pressions - 但我不这样想。

Been digging around thinking I can use grep or regular expressions - but I guess not.

由于提前,

推荐答案

使用差异 COM 或任何你想要的:

Using diff or com or whatever you want:

diff  <(echo "$string1" ) <(echo "$string2")

格雷格的Bash的常见问题解答:进程替换

或命名管道

mkfifo ./p
diff - p <<< "$string1" & echo "$string2" > p

格雷格的Bash的常见问题解答:具有命名管道工作

命名管道也被称为一个FIFO

Named pipe is also known as a FIFO.

- 对自己是标准输入。

The - on its own is for standard input.

&LT;&LT;&LT; 是这里字符串。

&安培; ; ,但把它在后台

这篇关于击弦差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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