我正在编写一个 Tera Term 宏,我需要分配一个包含 '
和 "
的字符串变量。我已经查看了各种教程,但无法'没有找到关于如何做到这一点的提及,所以希望它存在。
这些字符串变量不起作用:
hello = "command1 argument1 "foo/hello/world.txt""
world = 'command2 argument2 'bar/hello/world.txt''
给出的语法错误:
通过实验,我发现可以混合和匹配单引号和双引号,以便允许其中之一,但不能同时允许两者。
这些字符串变量有效:
foo = "command1 argumen1t 'foo/hello/world.txt'"
bar = 'command2 argument2 "bar/hello/world.txt"'
最佳答案
我不确定字符串是否有转义字符(我搜索过但没有找到任何相关内容),但是我找到了一种方法来解决这个问题。我并不是说这是正确的方法,但至少它可能适合您的情况。
为了发送报价,我使用了 sendln 的 ASCII 值功能。 (send 函数中的实际文档)
FILE1='foo/hello/world.txt'
FILE2='bar/hello/world.txt'
sendln 'command1 argument1 ' 34 FILE1 34
sendln 'command2 argument2 ' 39 FILE2 39
测试上述宏会在终端中输入以下内容
command1 argument1 "foo/hello/world.txt"
command2 argument2 'bar/hello/world.txt'
关于macros - Tera Term 宏字符串中的转义字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25450692/