Solaris / OpenSolarisThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by wpeckham
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.
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
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by shivaa
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.
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
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.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by shivaa
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.