0

I'm new to tcl. I'm trying to run some commands with tcl script.

I searched online and came to know that we can run unix commands with tcl using exec

I executed the following;

perl -i -p -e 's/hello linux./hello fedora. /g;' sample1.txt

from the commandline and it worked. it replaced all the occurences of hello linux with hello fedora.

I tried executing the same command in my tcl script.

set result [exec perl -i -p -e 's/hello linux./hello fedora. /g;' sample.txt]

I got the below error :

child process exited abnormally

I also tried using sed command. I got the same error. I guess there is something wrong with the syntax. I searched online but i couldn't figure it out on my own.

1 Answer 1

2

' is not a grouping character in tcl. The equivalent grouping in tcl is {}. Therefore the correct statement is:

exec perl -i -p -e {s/hello linux./hello fedora. /g;} sample.txt

Or even:

exec perl -i -p -e "s/hello linux./hello fedora. /g;" sample.txt
Sign up to request clarification or add additional context in comments.

3 Comments

Precisely this. It can sometimes confuse people using sed or awk scripts precisely because the recipes that they're used to using include the Bourne Shell quoting of the script, but the same principle applies to everything one translates from shell to Tcl.
@slebtman I tried it.But i got the following error bash :syntax error : unexpected token '}'. for the 2nd option I got child process exited abnormally..i tried all the possible combinations like with " without " . with { without }. It doesn't work
"bash syntax error"? Are you sure you're executing the script with tcl? It works for me. You do realize that perl -i edits the file sample.txt in place and returns nothing (empty string) don't you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.