无法获得if语句的工作

时间:2017-04-23 04:22:21

标签: shell csh

无法弄清楚如何使用expect来获取csh if语句。

这行代码工作

if(4 > 3) echo "4 is greater than 3."

$ 4 is greater than 3.

这行代码不起作用

if (4 > 3) $myvar = 5

0: Command not found (i.e. myvar = 0)

这也不是

if (4 > 3) then $myvar = 5

IF: Improper then

我做错了什么?我最好在一行或某种程度上需要所有这些来将send命令转换为expect脚本。如果我不能在一行上使用\字符,我会使用吗?

1 个答案:

答案 0 :(得分:2)

您似乎将csh语法与Bourne shell语法混淆。

您使用set name = value分配变量。 $name = value不起作用(实际上,它也不适用于Bourne shell,它在name=value}。

多行then只需要if。将它留给单行if

全部放在一起:

if (4 > 3) set myvar = 5

或:

if (4 > 3) then
    set myvar = 5
endif
相关问题