ADB播放含括号音频文件报错:/system/bin/sh: syntax error: '(' unexpected
Hey there! I’ve run into this exact issue with special characters in filenames when using ADB commands—let’s get this sorted for you.
The Root Cause
The error /system/bin/sh: syntax error: '(' unexpected happens because parentheses () are special meta-characters in the shell. When you run your command directly from your local terminal, both your computer’s shell and the Android device’s shell try to parse these characters as part of command syntax, not as part of the filename. Your earlier escape attempts only handled one layer of parsing, which is why they didn’t work.
Simple & Reliable Solutions
Here are two easy ways to fix this:
1. Wrap the File URI in Single Quotes (Recommended)
Single quotes tell the shell to treat everything inside as a literal string—no special characters will be parsed. This is the cleanest approach:
adb shell am start -a android.intent.action.VIEW -d 'file:///storage/emulated/legacy/Downloads/Coyote (group).mp3' -t audio/mp3
Double quotes work too, but single quotes are safer here since they don’t interpret any characters inside (like variables or backslashes) at all.
2. Double-Escape the Special Characters
If you prefer using escapes instead of quotes, you need to escape twice: once for your local shell, and once for the Android shell. Each ( needs to become \\( and each space becomes \\ :
adb shell am start -a android.intent.action.VIEW -d file:///storage/emulated/legacy/Downloads/Coyote\\ \\(group\\).mp3 -t audio/mp3
This works because your local shell removes one layer of backslashes, passing the correctly escaped string to the Android shell.
Bonus: Test Directly in the Android Shell
To avoid dealing with two layers of shell parsing, you can first connect directly to the Android shell, then run the command there. Here’s how:
adb shell # Now you’re in the Android device’s shell am start -a android.intent.action.VIEW -d 'file:///storage/emulated/legacy/Downloads/Coyote (group).mp3' -t audio/mp3
In this case, you only need single quotes or a single layer of escapes since there’s no local shell interfering.
Why Your Earlier Escape Didn’t Work
When you used Coyote\ \(group\).mp3, your local shell stripped off one set of backslashes before sending the command to Android. The Android shell received Coyote (group).mp3, which still has unescaped parentheses—hence the syntax error. Double-escaping or using quotes avoids this issue entirely.
内容的提问来源于stack exchange,提问作者Jaz

