如何在 ADB shell 中使用 if 比较 2 个字符串

发布于 2024-11-13 22:57:15 字数 232 浏览 5 评论 0原文

如何在 ADB shell 中使用 if 比较 2 个字符串, 我正在尝试使用 :

if ["a" = "a"];
then
fi

这给出了一个错误 [: not find

我尝试了 if 的所有变体,得到了相同的错误,

甚至只是

if [];
then
fi 

给出了相同的答案。

How to use if in comparing 2 strings in ADB shell,
I am trying to use :

if ["a" = "a"];
then
fi

this gives an error [: not found

I tried all the varients of if , got the same error,

even just

if [];
then
fi 

is also giving the same answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヤ经典坏疍 2024-11-20 22:57:15

如果在括号内添加空格会怎么样,如下所示:

if [ "a" = "a" ]

What if you put spaces inside the brackets, like this:

if [ "a" = "a" ]
筱果果 2024-11-20 22:57:15

根据 http://developer.android.com/guide/developing/tools/adb .html,adb(Android 调试桥)使用 ash shell。

我没有 adb,但我的 Ubuntu 系统上有 ash。在该系统上,可以执行以下操作:

if [ "a" = "a" ]
then
    echo ok
fi

在 adb shell 中尝试精确代码,包括所有间距。特别是 [ 周围和 ] 之前的空格是强制性的。

请注意,] 后面的分号不是必需的;可能没问题,但为了确定起见,请删除它。 (你说你“尝试了所有类似的东西”。不要尝试“类似的东西”;试试这个。)

你确定你在 shell (adb shell) 中而不是在 adb 本身? (我不知道 adb 是否有交互模式,所以这可能没有意义。)

According to http://developer.android.com/guide/developing/tools/adb.html, adb (Android Debug Bridge) uses the ash shell.

I don't have adb, but I do have ash on my Ubuntu system. On that system, the following works:

if [ "a" = "a" ]
then
    echo ok
fi

Try that exact code in your adb shell, including all the spacing. In particular the spaces around the [ and preceding the ] are mandatory.

Note that the semicolon after the ] is not required; it's probably ok, but delete it just to be sure. (You said you "tried all the similar stuff". Don't try "similar stuff"; try this.)

Are you sure you're in the shell (adb shell) and not in adb itself? (I don't know whether adb has an interactive mode, so that might not make sense.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文