string - 在 Bash 中比较两个字符串时出现 "command not found"错误

标签 string bash if-statement syntax compare

目前我的整个脚本是这样的:

#!/bin/sh   
clear;   
blanko="";   
# Dummy-Variablen
variable=Testvariable;   
if [[$variable == $blanko]];
then   
  echo "Nichts da!"   
else   
  echo $variable   
fi

如果我输入

TestSelect.sh

我明白了

/usr/bin/TestSelect.sh: line 6: [[Testvariable: command not found   
Testvariable

我该如何解决这个问题?

最佳答案

这是个问题:

if [[$variable == $blanko]];

方括号内需要空格,这样使用:

[[ "$variable" == "$blanko" ]] && echo "Nichts da!" || echo "$variable"

关于string - 在 Bash 中比较两个字符串时出现 "command not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19733437/

相关文章:

php - 在 PHP 中测试 UTF-8 字符串是一种可靠的方法吗?

c - 如何重写我的 if 语句才能工作?

excel - VBA:计数出现一对值的次数

bash - if [] 中 "[: too many arguments"错误的含义(方括号)

Java:流、读取器、字符缓冲区、字符串生成器等之间可能的泛化?

python - 将字符串中每次出现的子字符串替换为随机生成的值

c - C 语言的翻译限制

ruby - 这个 Ruby 代码和 shell 代码有什么区别?

linux - 如何在没有行号或 ASCII 表的情况下仅打印来自 hexdump 的十六进制值?

bash - 我什么时候可以在 Bash 中使用 |&?它可以在其他 shell 中使用吗?