user3587025
user3587025

Reputation: 183

how to run unix command with tcl/expect

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.

Upvotes: 0

Views: 2147

Answers (1)

slebetman
slebetman

Reputation: 114024

' 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

Upvotes: 3

Related Questions