bash脚本 - 参数太多 [英] Bash script - too many arguments

查看:241
本文介绍了bash脚本 - 参数太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么没有了以下工作?所有我想要做的是执行亚行命令,如果响应包含特定字符串,然后做一些事情。

Why doesn't the following work? All I'm trying to do is execute a adb command and, if the response contains a certain string, then doing something about it.

我不断收到一个错误 [;参数太多

VARIABLE=$(adb devices);
if [ "$VARIABLE" == *list of attached* ]; then
  echo "adb command worked";
fi

任何想法?

推荐答案

尝试引用的论据里面 [[和]]

VARIABLE="$(adb devices)"
if [[ "$VARIABLE" == *"list of attached"* ]]; then
  echo "adb command worked";
fi

== 需要在左右两侧单独的参数。当您使用 [$变量== *的名单附后*] 然后 *名单是第一个参数后, == 和休息被认为是额外的参数。

== needs single argument on either side. When you use [ "$VARIABLE" == *list of attached* ] then *list is the first argument after == and rest are considered extra arguments.

这篇关于bash脚本 - 参数太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆