我试图在tclsh中使用tcl exec diff在两个字符串上生成相同的diff命令输出。
请您告诉我如何使用tclsh exec diff
解决此示例使用Bash
$ diff <(echo "Testword") <(echo "Testword2")
1c1
< Testword
---
> Testword2
TCL失败
set str1 "Testword"
set str2 "Testword2"
首次尝试
% exec diff <(echo "$string1") <(echo "$string2")
extra characters after close-quote
第二次尝试
% exec diff <(echo \"$string1\") <(echo \"$string2\")
couldn't read file "(echo": no such file or directory
第三次尝试
% exec diff \<(echo \"$string1\") \<(echo \"$string2\")
couldn't read file "(echo": no such file or directory
第四次尝试
% set command [concat /usr/bin/diff <(echo \\"$string1\\") <(echo \\"$string2\\")]
/usr/bin/diff <(echo \"Malli\") <(echo \"Malli1\")
% exec $command
couldn't execute "/usr/bin/diff <(echo \"Malli\") <(echo \"Malli1\")": no such file or directory.
答案 0 :(得分:3)
这有点棘手,因为你依赖于bash功能 - 将<(some string)
转换为看起来像文件的东西 - 但是Tcl的exec不会调用bash或者自己进行这种转换。您可以通过从Tcl显式调用bash来使其工作:
% exec bash -c "diff <(echo '$string1') <(echo '$string2') || /bin/true"
1c1
< Testword
---
> Testword2
%
请注意