LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   The prompt in ash. (https://www.linuxquestions.org/questions/slackware-14/the-prompt-in-ash-4175538352/)

stf92 03-31-2015 02:50 PM

The prompt in ash.
 
Hi: I am using ash (just for fun). How do I do to have a prompt like the default in bash? That is, username@hostname:working directory path$. I've read the manual but cannot find the way to do it.

Didier Spaier 03-31-2015 03:30 PM

Just set the environment variables PS1 and PS2 as indicated in the manual.

Only the default value of PS1 differ between ash and bash as it is \s-\v\$ in bash but $ or # in ash for a regular user or root respectively, as stated in the manuals.

veerain 04-01-2015 01:30 AM

Run these in ash prompt:

Code:

export PS1='\u@\h \w $'

stf92 04-01-2015 08:05 AM

What I had done was to modify part of /etc/profile, namely:
Code:


# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
 PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
 PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
 PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
 PS1='$ '
else
 PS1='\u@\h:\w\$ '
fi

PS1='\u@\h:\w\$ '
PS2='> '
export PATH DISPLAY LESS TERM PS1 PS2

But I got literally the string as the prompt. But I can't remember the way
I made the system to use ash instead of bash. I presume I used chsh.

m3bm3b 04-02-2015 01:18 PM

ash does not accept the escapes in PS1 that bash accepts.

But a similar thing can be accomplished by overriding "cd" with a shell function
so that it modifies the prompt whenever you change directory.
For example:

cd() { command cd "$@" && PS1="$USER@$HOSTNAME:$PWD\$ "; }
cd . # Set the prompt the first time.

The above assumes $USER and $HOSTNAME are set appropriately.
The "command" command in ash allows the shell function to invoke the
built-in "cd" command; it is the equivalent of "builtin" in bash.


All times are GMT -5. The time now is 01:49 AM.