Reputation: 1111
I am trying to produce same output of diff command in tclsh using tcl exec diff on two strings.
Could you please let me know how to solve this example using tclsh exec diff
Working with Bash
$ diff <(echo "Testword") <(echo "Testword2")
1c1
< Testword
---
> Testword2
Failed on TCL
set str1 "Testword"
set str2 "Testword2"
First attempt
% exec diff <(echo "$string1") <(echo "$string2")
extra characters after close-quote
Second attempt
% exec diff <(echo \"$string1\") <(echo \"$string2\")
couldn't read file "(echo": no such file or directory
Third attempt
% exec diff \<(echo \"$string1\") \<(echo \"$string2\")
couldn't read file "(echo": no such file or directory
Fourth attempt
% 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.
Upvotes: 2
Views: 446
Reputation: 4382
This is a little tricky because you are relying on a bash feature - converting <(some string)
to something that looks like a file - but Tcl's exec does not invoke bash or do this conversion by itself. You can make it work by explicitly calling bash from Tcl:
% exec bash -c "diff <(echo '$string1') <(echo '$string2') || /bin/true"
1c1
< Testword
---
> Testword2
%
Note that
Upvotes: 3