bash中的字符串比较不起作用 [英] String comparison in bash is not working
本文介绍了bash中的字符串比较不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是bash脚本的新手.刚写了这个简单的程序,但是它抛出错误.
Hi I'm new to bash scripting. Just wrote this simple program but it is throwing error.
#!/bin/bash
os=`uname -o`
echo $os
if ["$os"=="GNU/Linux"] ; then
echo "Linux"
else
echo "Windows"
fi
在两种情况下都使用==或-eq时出现以下错误,并且正在打印else condn.
Using == or -eq for both cases I'm getting the following error and it is printing the else condn.
./ostype.sh:第3行:[GNU/Linux == GNU/Linux]:没有这样的文件或目录
Windows
bash版本:GNU bash,3.2.48(1)-发行版(x86_64-suse-linux-gnu)
Bash version : GNU bash, version 3.2.48(1)-release (x86_64-suse-linux-gnu)
推荐答案
尝试
if [ "$os" = "GNU/Linux" ]
请注意空格和单个=
.
[
实际上是一个程序,其余为参数!
[
is actually a program, and the rest are arguments!
这篇关于bash中的字符串比较不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文