adb shell su -c
is a commonly used adb command. Normally you just need to append arguments to the command line like this:
adb shell su -c echo ab
However, things can be tricky if you want to add quotes. For example, to print a b
(there are 2 spaces), these won't work:
adb shell su -c echo "a b"
adb shell su -c "echo \"a b\""
adb shell su -c "echo 'a b'"
You have to use these:
adb shell su -c "\"echo \\\"a b\\\"\""
adb shell "su -c \"echo \\\"a b\\\"\""
adb shell su -c "\"echo 'a b'\""
adb shell "su -c \"echo 'a b'\""
I'd like to know which is the standard way of writing such a command. Standard means it handles quotes correctly and in the most straightforward way.
My current research:
adb
handles command arguments the same way asssh
: Arguments are connected (with space) into a string, and that string is executed.su -c
expects a single string as the command line, and it doesn't do the concatenation for you.
So I think the most standard way of writing adb shell su -c
should be like:
adb shell "su -c \"echo \\\"a b\\\"\""
However, I'm not very confident about this. Does anyone have concrete reference confirming what I'm doing or showing I'm doing it wrong?