setting prompt for sh shell

hi, folks! i've got a little problem.. i'm setting my sh prompt, but
Code:
PS1="[\u@\h:\W, \@, \d]> "
doesn't seems to work... how can i fix it?
thx in advance!
 
As SirDice said: although on Linux systems sh usually means bash, on FreeBSD systems sh really means plain sh.

If I'm not mistaken sh doesn't have fancy bash-style prompts, you can only set PS1, PS2 etc. to constant strings. Come to think of it, sh lacks many things found in bash. Plain sh(1) (as found on FreeBSD) is meant primarily for scripting, not so much for interactive use. If you want an sh-style interactive shell, use shells/bash instead.

Fonz
 
killerklown said:
thx, i didn't know it.. I changed my shell to bash just for my user with chsh :P

Don't change root's shell to bash though. You can get yourself in a world of trouble when you're going to update your system.

Stick to (t)csh, it has most of the 'handy' features bash does but doesn't require anything to be installed.

A nice (t)csh prompt:
Code:
set prompt = "%n@%m:%~%#"
 
Or just use the toor account with a different shell. One gets used to [cmd=]su - toor[/cmd] in no-time.
 
You're trying to use something that's for bash. See sh(1).

Keep in mind that on FreeBSD /bin/sh is NOT bash (as it is on Linux).
No. In fact it's a perverse combination of Thompson, Bourne, and Almquist' shell. Only admitting to Almquist's ;-)
For those interested, Wikipedia has a Comparison of command shells that probably at least alludes to their history, and adoption. :)

Along the same vein, as the OP; Where can I find some options on creating at least a slightly more elegant prompt for sh(1) (ash)?

Thanks!

--Chris
 
Thanks for the reply, sidetone.
Probably not a bad idea, but I finally managed to cobble up something that provides the information I wanted. Namely;
(current|present) working directory (pwd(1), sometimes referred to cwd), newline, Hour:Minute, newline, Wkday Day, user@hostname.
OK that's gotta be hard to read. An example:
~
11:19pm
Wed, 01
me@myhost#

Anyway. It wasn't easy. But sh(1) gave me the pwd(1) with \w, and would have given me a couple of variations on hostname(1) (\H, or \h). But it's broken until, or unless I patch(1) up to r300642. I simply created a variable involving a date(1), and strftime(3) to produce the output I was interested in. But I was never able to utilize the C escape functions to returm a newline \n. So I had to kludge that. :-(.
I would have chosen a different shell, but my only interest was to get a little more information, when I drop to single-user mode. Which uses sh(1). So I was hoping to keep the changes to a minimum. Easier to maintain. :)

Thanks again, sidetone!

--Chris
 
It seemed like it could be done with sh(1), because there was an .shrc setting that had PS1 variables, but it did look complicated. I was doubtful that it absolutely couldn't be done. Can you post what you used for getting sh to show current pwd? Adding the time looks like a good adjustment for csh in root. From what I learned, different shells and their functions use different types of quotes, ' " and `. The backward single quote I believe is used in bash.

mksh uses the basic ' that's used the same way in shell script to get variables to work the way they do.

This is my .mkshrc for mksh
Code:
PS1='$USER:$PWD % '

* I barely realized the thread was restarted from an old one. But it's still good to resolve it.
 
Hey, sidetone. No problem.
Here ya go:
My original effort to get pwd(1), but only showed the directory it was originally started from
Code:
PS1="$(pwd) $(hostname) $(id -un) "
Final effort. pwd(1) is dynamic. But date, via time(1), is not.
Code:
newline="
"
# time is NOT dynamic
#cdate="$(date +%H:%S%p%n%a,%d)"
# Just use Wkday,Day
cdate="$(date +%a,%d)"
export CLICOLOR
PS1="\w $newline$cdate$newline`whoami`"
case `id -u` in
  0) PS1="${PS1}# ";;
  *) PS1="${PS1}$ ";;
esac
NOTE: I only added what was not already included in the FreeBSD default .profile.
I can post it in it's entirety, if you need/want. :)

Now. To figure out how to get the C style newline (\n) working. It's weird. I have no trouble doing it in shell scripts. I do it all the time. But, for the life of me, I can't seem to get done here. :-P

HTH

--Chris

P.S. It's the \w that gives you the pwd(1), in case it wasn't already obvious. :-)
 
Back
Top