What are special prompt symbols for busybox's sh support?

8,883

BusyBox has two shells, ash and hush. To see which one you have, run type chdir: ash has it as a builtin (synonymous with cd), hush doesn't. Both have an optional prompt expansion feature. Ash's is enabled by activating the ASH_EXPAND_PRMT feature at compile time, while hush requires FEATURE_EDITING_FANCY_PROMPT.

When that feature is present, in ash the value of PS1 is expanded like a double-quoted string: $foo, $(command) and `command` constructs are expanded.

Some backslash escapes are processed (in ash, after substitutions). They are a subset of bash's.

  • \!: line history count
  • \a: bell
  • \b: backspace
  • \e, \E: escape
  • \f: form feed
  • \h: host name
  • \n: newline
  • \r: carriage return
  • \t: tab
  • \u: user name (only with FEATURE_GETUSERNAME_AND_HOMEDIR)
  • \v: vertical tab
  • \w: current directory, with ~ for the home directory (only with FEATURE_GETUSERNAME_AND_HOMEDIR)
  • \W: current directory (unabbreviated)
  • \xHH or \XHH where HH are two hexadecimal digits: a character given by its hex code
  • \[…\]: the enclosed text doesn't count for width calculation purposes

(If you're looking at the source code, this happens in parse_and_put_prompt in libbb/lineedit.c.)

Share:
8,883

Related videos on Youtube

Daniel YC Lin
Author by

Daniel YC Lin

Code Worker

Updated on September 18, 2022

Comments

  • Daniel YC Lin
    Daniel YC Lin almost 2 years

    I want to setup a time prompt on PS1. But, there is no document about what are symbols the busybox support.

    Is there any one know? Here are all which I knew.

    PS1='\u@\h: \w \$'
    
  • user1730706
    user1730706 over 8 years
    Is there any way to fake this, maybe with printf, if it wasnt compiled in?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 8 years
    @StevenPenny To fake what? Backslash expansions can be faked with variable and command substitutions, but I think they're both enabled or disabled together. If they're absent, I don't think you can have a variable prompt, except by changing the value of PS1.
  • Admin
    Admin about 2 years
    Is there a way to know if that feature is set? In my router the backslash expansions like \e, \u and \w are working fine, but variables and $() are not. BusyBox v1.24.1, ash