LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-31-2015, 02:50 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
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.
 
Old 03-31-2015, 03:30 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,056

Rep: Reputation: Disabled
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.

Last edited by Didier Spaier; 03-31-2015 at 03:35 PM.
 
Old 04-01-2015, 01:30 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Run these in ash prompt:

Code:
export PS1='\u@\h \w $'
 
Old 04-01-2015, 08:05 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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.
 
Old 04-02-2015, 01:18 PM   #5
m3bm3b
LQ Newbie
 
Registered: Mar 2015
Posts: 1

Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
convert a bash to ash mdijoux25 Programming 6 02-25-2015 12:31 PM
[SOLVED] Bash to ash: Help converting a script? Mouse750 Programming 7 09-08-2011 01:32 PM
[SOLVED] Ash segfaults on second backspace 64-current GazL Slackware 15 04-02-2010 04:40 AM
Use bash as an alternative to ash? J_Szucs Linux - General 3 05-30-2005 04:44 AM
ash script (please) sourceman Linux - General 1 04-18-2002 09:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration