LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 12-01-2012, 04:12 PM   #16
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492

Quote:
Originally Posted by wpeckham View Post
What was the root shell before you hanged it?
I would expect it to be /bin/sh, but you should know.
root's default shell is not /bin/sh on Solaris. It is /sbin/sh and according to his posts, the OP already knows this.
Quote:
If it is the posix shell, or another shell acting in posix mode, you should be able to CREATE a file in the folder that root logon lands you, named .profile. On that folder set PS1 and then export it. I would not get complex here, just two simple lines should do the job.
Code:
PS1='..>'
export PS1
for example.
That is correct and will even work with Solaris non POSIX /sbin/sh. Just a side note, I wouldn't have suggested using this very prompt. The convention is to have something ending with '#' for root and with '$' for other users. '>' is a csh convention and is quite unfortunate, especially for root. I have seen production systems severely damaged after a miscontrolled cut and paste.
 
Old 12-02-2012, 12:04 AM   #17
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Thanks everyone for your kind responses!

FYI, I had creaeted a .bashrc in "/", so when root's shell is set to /bin/bash, then after opening a terminal, it loads the prompt properly from .bashrc and no issues. On the other hand, if I keep root's shell to /sbin/sh, and I invoke bash after openining the terminal, prompt again get set properly.
So there is no issues with .bashrc or /bin/bash. I think no further discussion needed on /bin/bash or .bashrc.

Unsolved questions:
(1) If root's shell is /sbin/sh, then which file comes into effect in order to set root's working environment ?
(2) Which one rules - /etc/profile or ~/.profile ?

I creaeted a .profile in "/", and changed root's shell back to /sbin/sh. This time I simply added following in ~/.profile:
Quote:
PS1='..>'
export PS1
But it's also not working, and system still gives me a "#" when I launch a new terminal. (I even rebooted the system, but nothing worked).
If I invoke "source .profile", then prompt metioned in .profile gets set. But source command (or even setenv, export etc) don't work when I open a new terminal, but I need to invoke "bash" or "tcsh" to get these commands work. So after invoking "bash" or "tcsh", I can use "source .profile" and prompt mentioned in it gets set properly.

FYI, Just after opening the terminal, if I check:
Quote:
echo $PS1
#
env | grep PS1
printenv | grep PS1
These commands returns nothing, except "echo $PS1", which returns a #. So if we consider that it's taking root's prompt from /etc/profile, then I checked and there's nowhere PS1 defined in /etc/profile!

As a conclusion, final question is, from where's it is taking/setting a "#" for root's PS1 variable when open a new terminal??

BTW, I am not a beginner in Solaris, so if anyone has any advanced solution, then you're most welcome!

Last edited by shivaa; 12-02-2012 at 12:14 AM. Reason: Typo
 
Old 12-02-2012, 03:23 AM   #18
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by shivaa View Post
Unsolved questions:
(1) If root's shell is /sbin/sh, then which file comes into effect in order to set root's working environment ?
/etc/default/login or /etc/default/su (only for the variables documented in that file)
/etc/profile (only for login shells)
/.profile (unless using a graphical environment configured to ignore it)
Quote:
(2) Which one rules - /etc/profile or ~/.profile ?
/etc/profile is read first for login shells but not for non login shells
/.profile (not ~/.profile as this syntax is unknown bin /sbin/sh) is eventually read (unless disabled, see next reply) so anything set here rules /etc/profile.
Quote:
I created a .profile in "/", and changed root's shell back to /sbin/sh. This time I simply added following in ~/.profile:
...
But it's also not working, and system still gives me a "#" when I launch a new terminal. (I even rebooted the system, but nothing worked).
Okay, one way to explain that behavior would be the last line of your /.dtprofile reading
Code:
 DTSOURCEPROFILE=false
Just change it to
Code:
 DTSOURCEPROFILE=true
and /.profile will be read at next login.
Quote:
If I invoke "source .profile", then prompt mentioned in .profile gets set. But source command (or even setenv, export etc) don't work when I open a new terminal, but I need to invoke "bash" or "tcsh" to get these commands work. So after invoking "bash" or "tcsh", I can use "source .profile" and prompt mentioned in it gets set properly.
source and setenv are not standard shell commands, thee first one is a bashism, the second one is a csh command. You should have used the "dot" command, i.e.
Code:
 . .profile
Quote:
As a conclusion, final question is, from where's it is taking/setting a "#" for root's PS1 variable when open a new terminal??
I already answered that one, it defaults to "#" or "$" depending on the user privileges when unset and this is hardcoded in the shell binary.
 
1 members found this post helpful.
Old 12-02-2012, 11:23 AM   #19
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
We're close !!

Hello, I feel we're now close to the solution...

I made following changes in .profile:
Code:
PS1=`who am i | cut -d" " -f1`{`pwd`}\!#   
export PS1
Then rebooted the system, opened a new terminal and it showed prompt:
Code:
root{/}!#
So clearly there was mistake in defining variable PS1 in .profile. But few more challanges left are:

(1) It do not show the command number (i.e. using \!#), but just printing it. Same is working fine in bash.
(2) It do not change the pwd, when I open a new directory, but keep it "/" only.
(3) I want a whitespace just after "#" in this prompt, but couldn't succeed. I left margin of a whitespace after # in .profile, but it didn't work.

I tried to close the PS1 value (i.e. `who am i | cut -d" " -f1`{`pwd`}\!#) within ' ', but then the prompt takes only literal, means prompt is:
Code:
`who am i | cut -d" " -f1`{`pwd`}\!#
`who am i | cut -d" " -f1`{`pwd`}\!#
If I enclose PS1 value within " " in .profile, thenn in prompt it shows values of variables/commands, but again not command number and changed working directory.

Last edited by shivaa; 12-02-2012 at 11:33 AM. Reason: Info added & typo
 
Old 12-02-2012, 11:58 AM   #20
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
If a recent version of bash is used, you have some short-cuts you can use:
Code:
PS1=”\u@\h: \W # ”
\u -> user,
\h -> hostname,
\W -> basename of the current working directory

There are a few more, have a look in the bash manual page (look for: PROMPTING).

If this is an older sun box and the above doesn't work, try this:
Code:
PS1='$LOGNAME@`hostname`:$PWD # '
Haven't used sunOS/Solaris in a while, but I'm sure jlliagre will straighten me out if I gave wrong/partially incorrect advise.....
 
Old 12-02-2012, 12:45 PM   #21
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Hello Druuna,
I have already tried all shortcuts like \u, \W, \H etc and even $USER, $PWD... And all are working fine with bash. But not with /sbin/sh.
Root's default shell is /sbin/sh, so when I open a new terminal, it reads /.profile and PS1 defined inside it gets set.

Rest, I have mentioned in my previous post (.. few more challanges left). Those couldn't be solved yet.

Last edited by shivaa; 12-02-2012 at 12:49 PM.
 
Old 12-02-2012, 03:39 PM   #22
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by shivaa View Post
Hello Druuna,
I have already tried all shortcuts like \u, \W, \H etc and even $USER, $PWD... And all are working fine with bash. But not with /sbin/sh.
There is no surprise they don't work. They are either bashisms or features introduced long after the original Bourne shell, which /sbin/sh essentially is, was developed. Should you want a dynamic prompt, you need to switch to a different newer shell like ksh or bash.
 
Old 12-04-2012, 10:41 PM   #23
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
I finally can conclude:
Prompt can be set in .profile, if shell is /sbin/sh. But older versions of shells have certain limitations, so it should be properly defined.
On the other hand, I have tested all /sbin/sh, /bin/bash, .bashrc and .profile. Now all are working fine after making little changes.

Thanks friends for your time & efforts!

Last edited by shivaa; 12-04-2012 at 11:03 PM. Reason: Thanks added
 
  


Reply

Tags
prompt, root



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
grub 2 - when / why I need both in grub.cfg ; set root= and search ... --set=root ... masuch Linux - Newbie 5 07-19-2012 03:41 PM
IRAF prompt cl - how do I set up key bindings? keflavich Linux - Software 1 12-18-2009 08:11 AM
[SOLVED] set timeout for ssh prompt vikas027 Programming 2 04-22-2008 03:35 PM
How to set tcsh prompt: # for root and % for user? robson Linux - Newbie 1 10-12-2003 03:13 PM
how set system time by command prompt? yenonn Linux - Newbie 9 08-25-2003 06:40 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 10:33 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