0

您好,我是 bash 脚本的新手,我有一个不适合我的简单程序。我认为它是一个语法错误。

#!/bin/bash
#example1.sh
read Age
if ["$Age" -lt "18"]; then
    echo "You must go to school"
fi

当我输入一个 1 它说 [1: command not found

4

2 回答 2

6

你需要空格:

if [ "$Age" -lt "18" ]; then

(总结:Bash 语法规则令人震惊。)

于 2012-06-11T11:37:21.630 回答
0
#!/bin/bash
#example1.bash

read Age
if(($Age < 18)); then
echo "You must go to school"
fi

此代码在 bash 中运行时有效。bash 和 sh 并不完全相同。

于 2013-06-18T04:55:09.143 回答