2011-11-21 87 views

回答

2

这里的工作bash的版本(而不是tcsh),给您的示例中的第一行:

#!/bin/bash 
mystring="0" 
if [ "$mystring" -eq "0" ]; then 
    echo "true" 
else 
    echo "wrong" 
fi 

注意,大部分的语法是对于bash略有不正确,即使逻辑看起来都正确。你还应该确定“mystring”是一个整数还是一个字符串类型 - 在这里我假设你期望字符串,并相应地修改了这个例子。

+0

同意,混合使用bash和tcsh。 OP,你想要什么?你的标题说tcsh。每个原始示例代码的elseif(elif)的任何变体都需要测试,例如'elif [[-f $ {fileToProcess}]];那么...' – shellter

1

如果您使用的是tcsh,那么您的if语法是错误的。如下使用

if ("$mystring" == "0") then 
commands 
else 
commands 
endif 

即使更改此设置后,您可能会遇到问题。它可以通过来解决,其源代码是,而不是在shell中输入它的名字。即,

$source script.sh 
instead of 
$script.sh