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.
Hello friends,
I have a Solaris 10 machine and I want to permanantly set root's prompt. By default it gives me "#" prompt for root. I couldn't find any .profile or .login or any shell initialization such as .bashrc or .cshrc file in root's home i.e. in "/".
I tried appending the prompt command in /etc/profile but it also worked only for cureent session. But it returns to # after openning new terminal.
Please suggest where to define root's prompt?
Thanks in advance!
I couldn't find any .profile or .login or any shell initialization such as .bashrc or .cshrc file in root's home i.e. in "/".
I tried appending the prompt command in /etc/profile but it also worked only for cureent session. But it returns to # after openning new terminal.
Try if you can find a PS1 at /etc/bashrc. If none then look from /etc/skel/.bash_profile. If none then force to use your own at /etc/skel/.bashrc_profile by creating it.
IIRC in my slackware a root from su uses a PS1 @ /etc/profile, and a root from login uses /root/.bashrc.
Hope that helps.
Good luck.
Last edited by malekmustaq; 11-28-2012 at 01:34 PM.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
root is not often configured to use bash on Solaris. It usually stays with its default shell which is /sbin/sh and is sometimes configured to use ksh, especially on Solaris 10. Solaris 11 finally use a POSIX shell for root.
/etc/profile or /.profile are correct places to set the prompt, please post what you wrote there and make sure PS1 is exported.
I do not use OpenSol myself, so I may be terribly full of it, but if it helps....
1. Generally / is not the root home folder on most Unix variants. More likely /root is the root home. If you have a .profile there you can use that to set the prompt.
2. Otherwise, look for a block in the /etc/profile that checks the UID and takes different actions if it is over or under some value. (Generally 500 or 1000.) Add your setting of the prompt to the block that includes LOW numbers.
3. Test. If that does not work, check back on later parts of the same file and/or login process to see if the value is being overwritten later. IF so, you might need to add later code and undo the earlier changes.
Obviously changing the thing found LAST in the process is better, so creating or modifying .profile in the root home is the preferable option. Earlier changes may be overwritten during upgrades or maintenance events, or may have consequences for other processes, users, or accounts.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by wpeckham
I do not use OpenSol myself
OpenSol (actually OpenSolaris) was discontinued a couple of years ago. The question here is about Solaris 10.
Quote:
1. Generally / is not the root home folder on most Unix variants. More likely /root is the root home.
While this is correct for most Gnu/Linux and *BSDs distributions, root has / as its home directory by default on Solaris, just like it does with AIX and HP-UX.
Quote:
2. Otherwise, look for a block in the /etc/profile that checks the UID and takes different actions if it is over or under some value. (Generally 500 or 1000.) Add your setting of the prompt to the block that includes LOW numbers.
You might won't find such code. Having userid 0's prompt being # and all other users being $ is hardcoded in the bourne shell. Moreover, if you switch to root by using su, the default prompt is reset to "# ".
Thanks everyone for your responses, here's summery what I've tried so far:
1. There are no /etc/.bashrc or /etc/bashrc files existing.
2. There is no /etc/.profile, but /etc/profile exists there.
3. In root's home (apparently it is "/" only), there is no .bashrc or .profile.
So in the meantime, I appended following in /etc/profile:
Code:
# Personalization
shell=`echo $SHELL`
if [ $shell -eq "/sbin/sh" ]; then
setenv PS1 "$USER{`pwd`}\!:"
elif [ $shell -eq "/bin/bash" ]
PS1="$USER{`pwd`}\!:"
export PS1
fi
But it also couldn't help, neither after sourcing /etc/profile nor when open a new terminal
4. I manually created /.bashrc and just added:
Code:
PS1="$USER{`pwd`}\!:"
export PS1
And when I switch shell to bash (just invoked bash cmd), .bashrc comes into effect & prompt get set properly & no issues with it.
So now quesiton is, what's initialization file for /sbin/sh shell? and is there any file which comes into effect before /etc/profile or /etc/.login to set root's prompt to "#"?
Last edited by shivaa; 11-30-2012 at 10:56 PM.
Reason: Info added
So now quesiton is, what's initialization file for /sbin/sh shell? and is there any file which comes into effect before /etc/profile or /etc/.login to set root's prompt to "#"?
To trigger /bin/sh as default shell use 'export'.
Does the /etc/profile get honored? Use your block to take "#" into effect: manipulate the setenv and elif lines:
Code:
# Personalization
shell=`echo $SHELL`
if [ $shell -eq "/sbin/sh" ]; then
setenv PS1="$USER{`pwd`}~# "
elif [ $shell -eq "/bin/bash" ]
PS1="$USER{`pwd`}~# "
export PS1
fi
Hope that works.
Good luck.
Last edited by malekmustaq; 11-30-2012 at 10:46 AM.
@malekmustaq: Please specify... Where? I want to set prompt for root user for his default /sbin/sh shell and want to know why it's not setting even after modifying /etc/profile. And now I am sure, there comes some other file into effect which takes over /etc/profile.
Also one more thing, when I open a terminal and do:
Code:
# echo $PATH
/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/usb
# which setenv source export
no setenv in /usr/sbin /usr/bin /usr/openwin/bin /usr/usb
no source in /usr/sbin /usr/bin /usr/openwin/bin /usr/usb
no export in /usr/sbin /usr/bin /usr/openwin/bin /usr/usb
And then if I invoke tcsh or bash, and do:
Code:
# tcsh
# echo $PATH
/usr/sbin:/usr/bin:/usr/openwin/bin:/usr/usb
setenv: shell built-in command
source: shell built-in command
export: Command not found
Could you understand, why this wierd behaviour since PATH variable is same in both cases?
Because what you added in /etc/profile is partially incorrect and has no effect, outside perhaps an error message.
Does changing the prompt message make any difference? I don't think so. I have tried what you suggested, but it also couldn't help.
Anyway, what I can conclude is, /etc/profile comes in effect first and takes over .bashrc for all types of users. If prompt is not set in /etc/profile, then it consults .bashrc for the same.
As a workaround I changed root's shell (in /etc/passwd) to /bin/bash and then it's working fine and using .bashrc & prompts cmd set in it. But I guess this could cause many other environment related problems for root. So this is temporary.
Do you have a local init script that loads automatically? Usually in Slackware it is located at /etc/rc.d/rc.local, this is the place where we can load some environment specifications or run scripts via init. If you have it in the /etc then set your export block there. But be sure that the tcsh is truly installed not just a link to /bin/bash. Check your shell availability first.
I'm sorry I already forget how it was when I was running Solaris, it was merely a brief time; when Sun sold open sol to Oracle I deinstalled and tried to forget everything. Solaris is the best unix I think; but I have natural allergy to copyrights .
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by shivaa
Does changing the prompt message make any difference? I don't think so.
I don't get what you mean here. Changing PS1 should definitely make a difference.
Quote:
I have tried what you suggested, but it also couldn't help.
What do you mean it couldn't help ?
Quote:
Anyway, what I can conclude is, /etc/profile comes in effect first and takes over .bashrc for all types of users.
This is incorrect. .bashrc is ignored when root is configured to use its default shell (/sbin/sh). When a user's shell is bash, .bashrc is processed after /etc/profile for login shells. Non login shell are not processing /etc/profile.
Quote:
If prompt is not set in /etc/profile, then it consults .bashrc for the same.
This is incorrect, if you are running bash, whatever set in .bashrc rules.
Quote:
As a workaround I changed root's shell (in /etc/passwd) to /bin/bash and then it's working fine and using .bashrc & prompts cmd set in it. But I guess this could cause many other environment related problems for root. So this is temporary.
There is actually no serious risk changing default root shell. I often switch it to ksh on Solaris 10. In any case, you could have let the shell to be /sbin/sh and create a /.profile file with your customizations here. That would have worked for both login and non login shells which seems to be your initial issue.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by malekmustaq
Do you have a local init script that loads automatically? Usually in Slackware it is located at /etc/rc.d/rc.local, this is the place where we can load some environment specifications or run scripts via init.
Beware not to confuse further the OP. There is no rc.local with Solaris and PS1 is not set by any init scripts.
Quote:
But be sure that the tcsh is truly installed not just a link to /bin/bash.
I don't think the OP ever mentioned tcsh. Linking it with /bin/bash would be a very bogus idea. In any case, tcsh doesn't make use of /etc/profile or .profile. It uses files named .login and .cshrc.
What was the root shell before you hanged it?
I would expect it to be /bin/sh, but you should know.
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.
(Note: on some systems /bin/sh is really a link to bash, ksh, or another shell. When called this way they should behave in posix mode, but the degree to which this is constrained varies. In reality they all act differently: the shell man pages should be your definitive guide.)
You will NOT find export in your path, it is a shell internal. Some shells implement commands that CAN be found in the path with internal equivalents that either run faster, behave better, have added functionality, or all of the above. Seeking them in your path really does nothing useful for you. To complicate things even more, different shells often implement different internals. Here again, your man pages should guide you.
BTW: export makes environment variables more generally available to called processes and sub-processes, it has NOTHING to do with changing your default shell. I am not sure where that idea originated.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.