Seeking help with how to escape "&" in ADB command line -- any guidance would be much appreciated!

I am attempting to extract .epub book files from an Android tablet running B&N Nook app. The NOOK app stores ebook files in "/data/data/bn.ereader/files/B&N Downloads/Books" The "B&N Downloads" string is causing problems in ADB shell commands. I have tried escaping the "&" and "space" in the following ways ...

$ ./adb shell cd ./data/data/bn.ereader/files/B&N Downloads/Books (original command)
$ ./adb shell cd ./data/data/bn.ereader/files/B\&N\ Downloads/Books
$ ./adb shell cd ./data/data/bn.ereader/files/'B&N Downloads'/Books
$ ./adb shell cd './data/data/bn.ereader/files/B&N Downloads/Books'
$ ./adb shell cd ./data/data/bn.ereader/files/"B&N Downloads"/Books
$ ./adb shell cd ./data/data/bn.ereader/files/B^&N^ Downloads/Books
(that last from suggestion in another answer: Trying to give "&" as part of adb shell input text)

always resulting in the same error ...

/system/bin/sh: N: not found
/system/bin/sh: cd: /data/data/bn.ereader/files/B: No such file or directory

ADB computer:
MacBookPro 9,2 (mid-2012)
System Version: macOS 10.14.6 (18G9323) "Mojave"
Kernel Version: Darwin 18.7.0.

Target Android device:
B&N Nook HD+ (running CyanogenMod)
Android version: 7.1.1
Kernel version: 3.0.101 (dmaces@gc-xenial #1)
Build Number: cm_ovation-userdebug 7.1.1 NMF26Q 161222 test keys

Also tried this on a Lenovo Tab M10 Plus 3rd Gen with the same results:
Android version: 12
Kernel version: 4.14.186-ga2e751134649
Build Number: TB125FU_S000118_220927_ROW

[NOTE: I have completed my original task by simply executing a "pull" of the whole darn directory tree above the problem "B&N Downloads" folder, but the issue of how to escape "&" remains]

  • Have you considered putting the whole shell command in single quotes (and escaping the & ? I believe youneed to escape everything twice. An alternative might be to double escape thr & character - ie \\\& so the single escaped & is passed to the shell, where it is escaped. ( all of this untested as Im not near a PC - so its a comment)
    – davidgo
    Dec 2, 2022 at 19:58
  • Thank you @davidgo -- as soon as I saw your suggestion I realized that was exactly what I needed to do: escape the escape so it would get passed on to the Android shell. Worked great! Thanks.
    – tbroad
    Dec 4, 2022 at 22:33

2 Answers 2


See the post adb shell input text does not take & ampersand character.

The accepted answer says this :

You need to encapsulate your string in quotes and escape your ampersand `"hello&hello"

Another answer was : hello1"&"hello2.

Still another answer remarked this :

( ) < > | ; & * \ ~ " ' and space all need escaping.
Space can be replaced with %s.


Solution to this problem was posted as a comment by @davidgo ...
Double escape the & character - ie \\\& so the single escaped & is passed to the shell, where it is escaped. Hence the command is:
./adb shell cd ./data/data/bn.ereader/files/B\\\&N\\\ Downloads/Books
Works great!

Alternative #2 that I discovered is:
$ ./adb shell (which puts the console into shell mode on the Android device)
# cd data/data/bn.ereader/files/B\&N\ Downloads/Books/

An bonus to alternative #2 is that tab auto-complete on the Android now works also. Caution: ANY error in the Android shell mode appears to abort that mode and return the console control to client terminal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .