# setting prompt for sh shell



## killerklown (Aug 15, 2011)

hi, folks! i've got a little problem.. i'm setting my sh prompt, but 
	
	



```
PS1="[\u@\h:\W, \@, \d]> "
```
 doesn't seems to work... how can i fix it?
thx in advance!


----------



## SirDice (Aug 15, 2011)

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).


----------



## fonz (Aug 15, 2011)

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 (Aug 15, 2011)

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


----------



## UNIXgod (Aug 15, 2011)

killerklown said:
			
		

> thx, i didn't know it.. I changed my shell to bash just for my user with chsh



sh is the most cut down. You can use csh, bash, zsh etc for interactive and prompts.


----------



## SirDice (Aug 16, 2011)

killerklown said:
			
		

> thx, i didn't know it.. I changed my shell to bash just for my user with chsh



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:

```
set prompt = "%n@%m:%~%#"
```


----------



## bes (Aug 16, 2011)

How about to add color :

```
set prompt="(%l)[%{\033[36m%}`whoami`@%{\033[1;30m%}%m:%{\033[0;32m%}%~%{\033[0m%}]%# "
```



> Don't change root's shell to bash though.


/me subscribe to this opinion .

But if you really want something other than (t)csh for root , have a look at this: https://forums.freebsd.org/showpost.php?p=127170&postcount=8


----------



## DutchDaemon (Aug 16, 2011)

Or just use the toor account with a different shell. One gets used to [cmd=]su - toor[/cmd] in no-time.


----------



## Chris_H (Jun 2, 2016)

SirDice said:


> 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


----------



## sidetone (Jun 2, 2016)

shells/mksh can do it too, by customizing .mkshrc in your home directory.


----------



## Chris_H (Jun 2, 2016)

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


----------



## sidetone (Jun 2, 2016)

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 
	
	



```
PS1='$USER:$PWD % '
```

* I barely realized the thread was restarted from an old one. But it's still good to resolve it.


----------



## Chris_H (Jun 2, 2016)

Hey, sidetone. No problem.
Here ya go:
My original effort to get pwd(1), but _only_ showed the directory it was _originally_ started from

```
PS1="$(pwd) $(hostname) $(id -un) "
```
Final effort. pwd(1) _is_ dynamic. But date, via time(1), is not.

```
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. 

HTH

--Chris

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


----------

