Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您好,我是 bash 脚本的新手,我有一个不适合我的简单程序。我认为它是一个语法错误。
#!/bin/bash #example1.sh read Age if ["$Age" -lt "18"]; then echo "You must go to school" fi
当我输入一个 1 它说 [1: command not found
你需要空格:
if [ "$Age" -lt "18" ]; then
(总结:Bash 语法规则令人震惊。)
#!/bin/bash #example1.bash read Age if(($Age < 18)); then echo "You must go to school" fi
此代码在 bash 中运行时有效。bash 和 sh 并不完全相同。