TCL脚本空格敏感

今天在linux shell中运行如下tcl(tool command language)脚本:

set gates [list and or not nand nor xor]
set index 1

foreach element $gates{#请注意花括号前没有空格是错误的
    puts "Gates $index in the list is $element"
    incr index
}

结果发现没有安装tcl解释器:

sudo apt install tcl安装之后再次运行,报如下错误:

结果一直没找到原因,文心一言居然没看出来,chatgpt看出来了但没说明白,尝试如下代码也不行

set gates [list and or not nand nor xor]
set index 1

foreach element $gates
{#即使这一行花括号前有空格也不行
    puts "Gates $index in the list is $element"
    incr index
}

最后才发现是花括号前面的空格问题:

set gates [list and or not nand nor xor]
set index 1

foreach element $gates {#注意前面有空格
    puts "Gates $index in the list is $element"
    incr index
}

修改成上面的代码后运行输出如下:

Gates 1 in the list is and
Gates 2 in the list is or
Gates 3 in the list is not
Gates 4 in the list is nand
Gates 5 in the list is nor
Gates 6 in the list is xor

总结:

在Tcl中,空格在脚本中有着重要的作用,因为Tcl的解析是基于空格的。Tcl中空格主要用于空格用于分隔命令和参数。每个单词(命令或参数)由空格或其他空白字符分隔。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值