嗨,我刚开始使用bash脚本。刚刚编写了这个简单的程序,但它正在抛出错误。
#!/bin/bash
os=`uname -o`
echo $os
if ["$os"=="GNU/Linux"] ; then
echo "Linux"
else
echo "Windows"
fi 对于这两种情况,我都使用==或-eq,我得到了以下错误,并且它正在打印or。
./ostype.sh:第3行: GNU/Linux==GNU/Linux:没有这样的文件或目录
Windows
bash版本: GNU,版本3.2.48(1)-release (x86_64-suse gnu)
发布于 2012-12-19 09:34:39
试一试
if [ "$os" = "GNU/Linux" ]注意空格和单个=。
[实际上是一个程序,其余的都是参数!
发布于 2012-12-19 09:33:51
使用=进行字符串比较。请参阅:http://tldp.org/LDP/abs/html/comparison-ops.html
此外,在方括号和比较运算符周围应有一个空格,即
if [ "$os" = "GNU/Linux" ]; then
^ ^ ^ ^ ^
| | | | |
\-\-----\-\-----------\-- (need spaces here)https://stackoverflow.com/questions/13949260
复制相似问题