Tcl/Expect中利用exec调用管道"|"和awk的注意事项
2010-08-03 20:52
513 查看
Tcl/Expect中利用exec调用稍微复杂的shell命令时,经常会遇到一些小问题,常见的就是pipeline(|)和awk。
Tcl/Expect调用多个shell命令并使用|将其串接在一起时,需要注意的是必须在"|"前后加上空格" ",否则tcl/Expect会报奇怪的错。
Tcl/Expect调用awk命令时,需要把awk的' '中的命令改为用" ",并把$1, $2之类的变量改为/$1, /$2。
下面的ksh命令判断test_process是否在运行:
改为Tcl/Expect后,为:
另外, http://www.linuxquestions.org/questions/linux-software-2/ksh-tcl-173092/ 列出了一些ksh命令转换为tcl语句时经常遇到的问题(本人未曾验证过,请谨慎使用)。
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 '(..$1..)' with "{../$1..}"
-----------------------------------------------------------------
ksh: ps -eaf | awk '(print $1}' | grep $1 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
-----------------------------------------------------------------
还有就是http://wiki.tcl.tk/1039列出了使用exec的一些常见问题。
Tcl/Expect调用多个shell命令并使用|将其串接在一起时,需要注意的是必须在"|"前后加上空格" ",否则tcl/Expect会报奇怪的错。
Tcl/Expect调用awk命令时,需要把awk的' '中的命令改为用" ",并把$1, $2之类的变量改为/$1, /$2。
下面的ksh命令判断test_process是否在运行:
ps -fu bonny|grep -v ps|grep MMCAP|grep -v grep|awk '{print $2}'
改为Tcl/Expect后,为:
exec ps -fu $myname | grep -v ps | grep COOLrunMMCAP | grep -v grep | awk "{print /$2}"
另外, http://www.linuxquestions.org/questions/linux-software-2/ksh-tcl-173092/ 列出了一些ksh命令转换为tcl语句时经常遇到的问题(本人未曾验证过,请谨慎使用)。
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 '(..$1..)' with "{../$1..}"
-----------------------------------------------------------------
ksh: ps -eaf | awk '(print $1}' | grep $1 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
-----------------------------------------------------------------
还有就是http://wiki.tcl.tk/1039列出了使用exec的一些常见问题。
相关文章推荐
- Tcl或sh调用 exec调用管道”|”和awk的注意事项 + shell返回值如何赋值给tcl变量
- java split(".");注意事项
- 使用eclipse 开发 嵌入式Linux驱动(注意事项)(make:***没有规则可言创建目标"all".停止 的解决方法)
- java split(".");注意事项
- 使用class.getClassLoader().getResource("")的注意事项
- WPF:自动执行"机器人"程序若干注意事项(转载)
- iOS 字符串长度计算boundingRectWithSize遇到 " \r\n"的时候,后面的字符串长度返回0 在swift中使用pod导入第三方库时,注意事项
- java Runtime.getRuntime().exec 调用系统脚本/命令注意事项
- C++ 调用 python 注意事项(转)
- 【iOS-Cocos2d游戏开发之九】讲解CCSpriteBatchNode与TP工具的".pvr.ccz",".plist"共用的终极精灵优化及注意事项!
- Request.Cookies["User_ID"]使用注意事项
- java Runtime.getRuntime().exec 调用系统脚本/命令注意事项
- awk中调用shell变量注意事项
- java split(".");注意事项
- 【nginx】nginx proxy_pass指令"/"注意事项
- 使用class.getClassLoader().getResource("")的注意事项
- android中利用webview调用网页上的js代码和注意事项
- 【iOS-Cocos2d游戏开发之九】讲解CCSpriteBatchNode与TP工具的".pvr.ccz",".plist"共用的终极精灵优化及注意事项!
- WebView注入Java对象注意事项 [INFO:CONSOLE(475)] "Uncaught TypeError: Object [object Object] has no method
- 关于使用<s:property value="">形式取得 数据库图片地址的注意事项