Android: Full documentation for the 'PS1' syntax used in 'adb shell'?
14:14 08 Sep 2026

NOTE: I'm posting here because I originally posted this question in the official Google Android discussion forum, but then I was told there that instead, I should post my question here. If that is still not correct and I yet again should go elsewhere, feel free to point me to the proper venue for asking the following question:

I'm running Android 13.

When I run adb shell in a USB connection from my desktop machine to my Android device, the following is the value of the PS1 variable that gets automatically set ...

${|
        local e=$?
        (( e )) && REPLY+="$e|"
        return $e
}$HOSTNAME:${PWD:-?} $

I can see how this particular setting of PS1 pretty much relates to the generated shell prompt in adb shell, but still want to know all of the details of PS1 syntax for adb shell.

Can anyone point me to the full documentation of PS1 as it's utilized in adb shell?

For example, one thing that I'd like to understand is how the vertical bars work within that PS1 setting. The second vertical bar *seems* (???) like it might indicate a termination of the text which follows the first vertical bar, even though this second vertical bar appears to be nested within a double-quoted string. But that's just a wild guess which might be totally incorrect. And whatever these vertical bars might *actually* mean, I'd still also like the full docs, so that I can understand *all* of the PS1 syntax that's used in adb shell.

Also ... if I re-set PS1 to be the same value as above, except with the vertical bars removed, I then always get the following error message when running every command that is run within adb shell ...


: can't create temporary file /data/local/shXXXXXX.tmp
: Permission denied

... where "XXXXXX" are 6 randomly generated base-36 characters, and where the displayed shell prompt is then only a single dollar sign. Therefore, these vertical bars relate to file/directory access permissions, *maybe* (???) involving some kind of evaluation being performed as root.

And yet again -- just to be clear -- I want more than only the meaning of those vertical bars. I'm looking for the *full* PS1 syntax documentation for adb shell.

And ... if it turns out that there is no such full documentation for PS1 as used by adb shell, could perhaps someone point me to the official Google source code for ADB itself and/or the official Google source code specifically for the shell that's used within ADB sessions?

advice android shell adb ps1