使用 Tcl 在 if 语句中评估表达式为真 [英] evaluating an expression to true in a if statement with Tcl

查看:41
本文介绍了使用 Tcl 在 if 语句中评估表达式为真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力弄清楚如何使用 Tcl 计算 If 语句中的表达式.这就是我所拥有的:

I'm having serious biggies trying to figure out how to evaluate an expression in a If statement using Tcl. This is what I have:

#!/bin/sh
#The next line executes wish - wherever it is \
exec wish "$0" "$@"

set apid "/var/run/apache2.pid"

set apsta [file exist $apid]

if { $apsta == 1 }

{
    set result ":)"
}

else

{
    set result ":("
}

label .status -text $result
pack .status

这是我从终端得到的:

# wan27
Error in startup script: wrong # args: no script following " $apsta == 1 " argument
    while executing
"if { $apsta == 1 }"
    (file "/usr/bin/wan27" line 9)

如果 Apache 正在运行,我只是想输出一个快乐的笑脸,如果 Apache 停止则输出一个悲伤的笑脸 - 基于文件/var/run/apache2.pid"是否存在的布尔条件......

I'm just trying to output a happy smiley if Apache is running, a sad one if Apache is stopped - based upon the boolean condition whether or not the file "/var/run/apache2.pid" exists ...

推荐答案

Tcl if 语句的语法是

The syntax of a Tcl if statement is

if condition statement else statement

必须在一行上.大括号允许跨行延续,并且它们的位置是强制性的:

which must be on one line. Braces allow continuation across lines and their placement is mandatory:

if { $apsta == 1 } {
    set result ":)"
} else {
    set result ":("
}

正如你所写的,Tcl 看到了

As you have it written, Tcl sees

if { $apsta == 1 }

并在那里停止产生语法错误.

and stops there yielding a syntax error.

这篇关于使用 Tcl 在 if 语句中评估表达式为真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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