LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-24-2008, 11:12 AM   #1
moob8
Member
 
Registered: Sep 2006
Distribution: slackware
Posts: 132

Rep: Reputation: 15
root won't use bash as login shell


root won't use bash as the login shell. It uses sh. I verify this by two means:
  • the prompt is not in colors, indicating that my .bashrc is not being used for root
  • when I run screen and perfrom a ^-a " operation, the menu shows "sh", not "bash" for each screen name
Use of the chsh command indicates that root uses bash but it lies, as already determined above.

If I start a new root via su from a non-root term, this new root does use bash.

How do I force root to use bash? The solution will not involve recompiling the kernel nor changing my distro.
 
Old 10-24-2008, 11:55 AM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by moob8
the prompt is not in colors, indicating that my .bashrc is not being used for root
The .bashrc is not read for login shells. So the fact that is not read when you invoke a login shell is the expected behaviour.

Extract from the bash man page:

Quote:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.
Edit:
It is fairly common practice to parse .bashrc from .bash_profile so .bashrc thus causing .bashrc to be used for login shells as well as non-login shells.


If you want to know what shell you're using you do this:

Code:
mike@continuity:~$ echo $0
/bin/bash
You can also check the shell entry in /etc/passwd

Code:
mike@continuity:~$ grep ^root /etc/passwd
root:x:0:0:root:/root:/bin/bash
Quote:
Originally Posted by moob8
The solution will not involve recompiling the kernel nor changing my distro.
I think you mean that you would prefer a solution that doesn't involve recompiling the kernel or changing distro. Since you don't know what the solution is, you are not in a position to state that the solution will not involve either of these.

Last edited by arizonagroovejet; 10-24-2008 at 11:57 AM.
 
Old 10-24-2008, 12:13 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by moob8 View Post
root won't use bash as the login shell. It uses sh. I verify this by two means:
  • the prompt is not in colors,[/code]

    Completely irrelevant. The prompt can be set on a per-user basis, and usually root uses a different prompt. It's indicative of nothing at all.

    indicating that my .bashrc is not being used for root
  • As the other poster above said, bashrc is not always read. It depends if it's a login or non-login shell. Read the section titled "INVOCATION" of the bash man page.

    Quote:
    when I run screen and perfrom a ^-a " operation, the menu shows "sh", not "bash" for each screen name
I don't know where does screen takes that info from. However, note that in most modern distros, /bin/sh (or /usr/bin/sh, or whatever) is usually a symlink to /bin/bash. You can check if that's your case with "ls -l /bin/sh".

Quote:
Use of the chsh command indicates that root uses bash but it lies, as already determined above.
This command, and the contents of /etc/passwd never lies.

If I start a new root via su from a non-root term, this new root does use bash.

Quote:
How do I force root to use bash? The solution will not involve recompiling the kernel nor changing my distro.
Standard procedure. The kernel is unrelated, as is the distro for the most part. It's the login manager which launches a given shell or desktop.

Last edited by i92guboj; 10-24-2008 at 12:16 PM.
 
Old 10-24-2008, 12:22 PM   #4
moob8
Member
 
Registered: Sep 2006
Distribution: slackware
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by arizonagroovejet View Post
I think you mean that you would prefer a solution that doesn't involve recompiling the kernel or changing distro.
That's what I meant and what I said. is there a problem here?

Quote:
Since you don't know what the solution is, you are not in a position to state that the solution will not involve either of these.
Nice attitude. Please have a nice day and never reply to this thread again, OK? Thank you.
 
Old 10-24-2008, 12:26 PM   #5
moob8
Member
 
Registered: Sep 2006
Distribution: slackware
Posts: 132

Original Poster
Rep: Reputation: 15
thanks for the information, all.

From the information in the helpful replies, it has been determined that there is, in fact, no sh on my system. It's all bash .,.. yet somehow bash acts differently, not reading certain files or reading certain files based on ... still parsing that. Very strange. As the nature of the problem has changed, it will have to go to another thread.
 
Old 10-24-2008, 01:32 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by moob8 View Post
thanks for the information, all.

From the information in the helpful replies, it has been determined that there is, in fact, no sh on my system. It's all bash .,.. yet somehow bash acts differently, not reading certain files or reading certain files based on ... still parsing that. Very strange. As the nature of the problem has changed, it will have to go to another thread.
All you need to know regarding what files are parsed is in the bash man page, INVOCATION section as I said above.

Some things to note are the following:
  1. As said, depending on whether the shell is a login shell or a non-login one, the parsed files are different.
  2. Some times, bash will not parse file Y if file X has been found first, even if X is an empty file. For example, when bash is invoked as a login interactive shell, it reads /etc/profile, and *after* that, it reads one (and only one!) of ~/.bash_profile, ~/.bash_login, and ~/.profile. They are probed in that order, and the first one that is found (and readable) will be used. That means that, if ~/.bash_profile do exist, then ~/.bash_login and ~/.profile will not be read. Even if ~/.bash_profile is an empty file.
  3. For non-login shells, ~/.bashrc is sourced.
  4. Check very carefully the ownerships, permissions and special attributes of the bash init files in each home directory (your user's and root's) and see if they are coherent. Be specially careful and check also if any of these files is a symlink to any other file, sometimes people do odd things, and then they just can't figure why they seem to have a mutant bash.

I hope you can find the problem.
 
Old 10-24-2008, 07:13 PM   #7
r0x0rj00b0x0r
LQ Newbie
 
Registered: Sep 2008
Distribution: Gentoo, Slackware at Home & RHEL and AIX at work.
Posts: 17

Rep: Reputation: 0
Sometime /bin/sh is a link to your default shell

booyah ~ $ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Oct 24 00:56 /bin/sh -> bash


You can always change that link or user usermod to change the default shell.


booyah ~ $ su -c 'usermod -s "/bin/bash" root'
Enter your password:

Hope this helps.

Last edited by r0x0rj00b0x0r; 10-29-2008 at 11:45 AM.
 
Old 10-24-2008, 07:28 PM   #8
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,333

Rep: Reputation: 547Reputation: 547Reputation: 547Reputation: 547Reputation: 547Reputation: 547
Quote:
Originally Posted by moob8 View Post

root won't use bash as the login shell. It uses sh.
sh is an alias for bash.

-----------------
Steve Stites
 
Old 10-26-2008, 06:15 AM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
That we know already

By the way, the default shell, if no shebang is included in the script, is the running one, and not the one symlinked to /bin/sh, so that's pointless.

And, if your use an #!/bin/sh shebang, then you should stick to the bourne shell syntax, so, the symlinked shell, again, is pointless.
 
Old 10-28-2008, 10:15 PM   #10
r0x0rj00b0x0r
LQ Newbie
 
Registered: Sep 2008
Distribution: Gentoo, Slackware at Home & RHEL and AIX at work.
Posts: 17

Rep: Reputation: 0
shebang = #!

# = shh ie shhh im commenting that out
! = BANG! ie my love goes bang bang bang ;-)

Last edited by r0x0rj00b0x0r; 10-28-2008 at 10:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Root user bash shell look like "bash-2.05b#" and /root empty y2pk001 Linux - Security 6 03-22-2007 08:33 PM
wrong login shell prevent root login cefs99 Linux - Security 4 05-31-2006 08:28 AM
login directly to bash shell openart Linux - Newbie 5 10-27-2004 08:05 AM
Rare problem - cant login into bash shell Xris718 Linux - General 2 07-16-2004 01:07 AM
How to login to bash shell inarin Linux - Newbie 1 10-07-2003 02:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:23 AM.

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