Using EXEC to invoke the pipe "|" in Tcl/expect and Awk's considerations

Source: Internet
Author: User

When Tcl/expect uses Exec to invoke a slightly more complex shell command, it often encounters minor problems, usually pipeline (|) and awk.

When Tcl/expect calls multiple shell commands and uses | To string them together, it is important to note that the "|" Before and after the sky "", otherwise tcl/expect will report strange mistakes.

When Tcl/expect invokes the awk command, you need to change the command in awk to "", and change the $ and $ variable to/$1,/$2.

The following Ksh command determines whether the test_process is running:

Ps-fu bonny|grep-v ps|grep mmcap|grep-v Grep|awk ' {print $} '

After changing to Tcl/expect, it is:

EXEC Ps-fu $myname | Grep-v PS | grep Coolrunmmcap | Grep-v grep | awk "{Print/$2}"

In addition, http://www.linuxquestions.org/questions/linux-software-2/ksh-tcl-173092/lists some of the problems that are frequently encountered when converting KSH commands into TCL statements (which I have never verified, Please use it carefully).

Here's some conversion rules that I have proven, if anyone has any more info (in any fashion), please advise.

-----------------------------------------------------------------
Rule:remove "
-----------------------------------------------------------------
Ksh:cat *.passwd 2>/dev/null | Cut-d ":"-F1 | Sort | Uniq
Tcl:exec Cat *.passwd 2>/dev/null | Cut-d:-f1 | Sort | Uniq
-----------------------------------------------------------------

-----------------------------------------------------------------
Rule:replace ' (.. $.) ' With "{.. /$1..} "
-----------------------------------------------------------------
Ksh:ps-eaf | awk ' (Print} ' | grep $2>&1
Tcl:exec Ps-eaf | awk "{print/$1}" | grep $user _login_to_test
-----------------------------------------------------------------

-----------------------------------------------------------------
Rule:replace "..." with {...}
-----------------------------------------------------------------
Ksh:grep "^$ (user_login:"/etc/passwd/etc/shadow 2>&1
tcl:exec grep {^ $user _login:}/etc/passwd/etc/shadow
-----------------------------------------------------------------

-----------------------------------------------------------------
Rule:replace ' ... ' with ' ... ' or {...}
-----------------------------------------------------------------
Ksh:grep ' Version ' USER.TCL
tcl:exec grep {Version} USER.TCL
tcl:exec grep "Version" USER.TCL
-----------------------------------------------------------------

And there's the http://wiki.tcl.tk/1039. Lists some common problems with exec.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.