TCL执行程序,列表中包含特殊字符 [英] TCL exec with special characters in list

查看:272
本文介绍了TCL执行程序,列表中包含特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有tcl程序,它执行存储在tcl列表中的命令. 例如:

There is tcl procedure which executes command stored in tcl list. For example:

catch { exec $list}

列表类似于:

--option1 op1 --option2 op2 --option3 op3 ...

选项"之一是如下所示的正则表达式:

One of options is regexp that looks like:

(.*[/\])?(sh|bash)(\.exe)?

由exec option替换后,如下所示:

After substitution by exec option looks like:

{(.*[/\])?(sh|bash)(\.exe)?}

但是我需要的是:

"(.*[/\])?(sh|bash)(\.exe)?"

在这种情况下我该怎么办?

What can I do in such situation?

推荐答案

将列表转换为字符串时,会将其转换为规范形式,然后将其转换回相同的列表.

When a list is converted to a string, it is converted to a canonical form that will convert back to the same list.

您看到的是用于确保规范形式正确转换回的引号字符.

What you are seeing are the quoting characters that are used to ensure that the canonical form converts back correctly.

所以该值是正确的.

exec $list仅将单个参数传递给exec. exec使用一系列单词作为参数,而不是包含单词的列表.

exec $list only passes a single argument to exec. exec takes a series of words as arguments, not a list which contains words.

exec命令应为:

catch { exec {*}$list }

{*}语法将列表转换为其组成词.

The {*} syntax converts the list into its component words.

在旧版本的tcl中,必须使用eval语句:

In older versions of tcl, the eval statement must be used:

catch { eval exec $list }

参考文献: exec {*}(Tcl的第5节)

这篇关于TCL执行程序,列表中包含特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆