"/system/bin/sh: syntax error: '(' unexpected" when specifying a file in ADB

"/system/bin/sh: syntax error: '(' unexpected" when specifying a file in ADB

最近一直在弄adb,主要是push命令。当 phone 不想像闪存驱动器一样安装时,它是一个救星。最近,我一直在将音频文件加载到 phone 上,并发现了一种简洁的单行代码,可以使 phone 从锁定屏幕播放音频。尝试了它,它在 /storage/emulated/legacy/Downloads/ 中名为“Wolves.mp3”的文件上完美运行,但是当我尝试名为 Coyote (group).mp3 的文件时,它给出了错误消息:

/system/bin/sh: syntax error: '(' unexpected

我尝试了很多不同的解决方案,例如从 file:///storage/... 更改为 /storage/...,根据 this site 转义符号,这只会让我更加困惑。我什至尝试使用常见的 \ 来转义符号 /storage/emulated/legacy/Downloads/Coyote\ \(group\).mp3 但即使这样也给出了完全相同的错误。

编辑

我运行的命令是这样的:

[jaz@Jaz-Jackson ~]$ adb shell am start -a android.intent.action.VIEW -d file:///storage/emulated/legacy/Downloads/coyote (group).mp3 -t audio/mp3

嘿,我想通了!!!

知道 file:// 协议用于超链接结构,我记得您通常的 url 会将 space 符号替换为字符串 %20,所以我将这首歌推送到我的另一个 phone,并将 spaces 替换为 %20,然后就可以了!现在我只需要用它们的超链接等价物替换所有特殊符号,例如 ()[]{}-+!@#$%^&*,这应该可以解决我所有的问题!

[jaz@Jaz-Jackson]$ adb shell am start -a android.intent.action.VIEW -d "file:///storage/self/primary/Music/Ra%20Ra%20RasPutin.mp3" -t audio/mp3
Starting: Intent { act=android.intent.action.VIEW dat=file:///storage/self/primary/Music/Ra Ra RasPutin.mp3 typ=audio/mp3 }

是的。在我的音乐中,我能找到的唯一一首没有任何特殊符号的歌曲是 Ra Ra RasPutin。虽然它有效!

工作解决方案:

  1. 直接使用adb命令时的解决方法是:
    adb shell am start -a android.intent.action.VIEW -d file:///storage/emulated/legacy/Downloads/coyote \(group\).mp3 -t audio/mp3

解释:这里adb是从android shell使用的,shell对()圆括号有特殊意义,所以出现上述错误。从而转义括号将解决它。

  1. 将 xargs 与 adb 命令一起使用时:
    echo "file:///storage/emulated/legacy/Downloads/coyote (group).mp3" | xargs -n1 -I {} adb shell am start -a android.intent.action.VIEW -d "{}" -t audio/mp3

但是这里echo "file:///storage/emulated/legacy/Downloads/coyote \(group\).mp3" | xargs -n1 -I {} adb shell am start -a android.intent.action.VIEW -d "{}" -t audio/mp3 Error: /system/bin/sh: Unexpected '('不行。

因为有一次圆括号用反斜杠转义,这解决了 android shell 问题,但反斜杠作为 xargs 计算机的特殊字符 shell 因此它也需要被逃脱。 所以解决方案将是: echo "file:///storage/emulated/legacy/Downloads/coyote \(group\).mp3" | xargs -n1 -I {} adb shell am start -a android.intent.action.VIEW -d "{}" -t audio/mp3