tclsh调用使用exec调用shell命令的时候经常出错,如
- 使用"|"串联多个命令的时候,必须前后加空格
- awk中‘’出错,必须改成“”, $1 $2不识别
- sed -i ‘$s/\//g’ rtl_source_file.list 不识别 s 符号等
有人列出了shell到tcl的exec需要进行调整的地方
https://blog.youkuaiyun.com/bonny95/article/details/5786283
https://www.linuxquestions.org/questions/linux-software-2/ksh-tcl-173092/
但是实践中还是很麻烦,两种比较方便的解决方案,是使用exec来执行sh,再用sh执行需要的命令
方案一:
使用exec sh -c {your commands here}
例如:
cat *.passwd 2>/dev/null | cut -d":" -f1 | sort | uniq
exec sh -c {cat *.passwd 2>/dev/null | cut -d":" -f1 | sort | uniq}
来源:https://www.linuxquestions.org/questions/linux-software-2/ksh-tcl-173092/
不过我在使用这种方法的时候,还是有时候可以有时候不可以,很奇怪。
方案二:
将shell命令写到一个可执行的shell脚本文件中,在tcl中使用exec ./shell_command.sh来执行shell命令。