[SOLVED] Customizing the login shell, It's possible?
SlackwareThis Forum is for the discussion of Slackware Linux.
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.
If wanting the changes global for all users, /etc/bashrc.
I think you're thinking of /etc/profile or the various files inside /etc/profile.d/. /etc/bashrc doesn't exist on my 14.2 system (maybe it's something new for -current?).
@Nick-us, I modify the PS1 variable in /etc/profile to do something very similar to yours. I colorize my hostname (each computer has a different color so I can easily see which one I'm logged into since I ssh around a lot). Also, if I am logged in as root, I will have root's username highlighted red to have that visual reminder that I can do some serious damage and be careful what I type.
Around line 50 is where they start changing the PS1 variable based on your shell (the line numbers might be off by a few due to additions I have in the file). On mine, line 61 is the PS1 for root and line 63 is the PS1 for any other user using bash. Including the if statement that starts for me on line 60, mine is as follows:
Code:
if [ "$UID" = "0" ]; then
PS1='\[\e[41m\]\u\[\e[49m\]@\[\e[36m\]\h\[\e[0m\]:\w\$ '
else
PS1='\u@\[\e[36m\]\h\[\e[m\]:\w\$ '
fi
So, this file allows you to modify the PS1 variable systemwide, but if you want a specific PS1 for a single user, that's when you'd use a ~/.bashrc like GazL and upnort mentioned or ~/.profile or ~/.bash_profile.
~/.bashrc will apply to any shell, including login shells, but ~/.profile and ~/.bash_profile will only apply to login shells, and not to any subshells.
I think you're thinking of /etc/profile or the various files inside /etc/profile.d/. /etc/bashrc doesn't exist on my 14.2 system (maybe it's something new for -current?).
@Nick-us, I modify the PS1 variable in /etc/profile to do something very similar to yours. I colorize my hostname (each computer has a different color so I can easily see which one I'm logged into since I ssh around a lot). Also, if I am logged in as root, I will have root's username highlighted red to have that visual reminder that I can do some serious damage and be careful what I type.
Around line 50 is where they start changing the PS1 variable based on your shell (the line numbers might be off by a few due to additions I have in the file). On mine, line 61 is the PS1 for root and line 63 is the PS1 for any other user using bash. Including the if statement that starts for me on line 60, mine is as follows:
Code:
if [ "$UID" = "0" ]; then
PS1='\[\e[41m\]\u\[\e[49m\]@\[\e[36m\]\h\[\e[0m\]:\w\$ '
else
PS1='\u@\[\e[36m\]\h\[\e[m\]:\w\$ '
fi
So, this file allows you to modify the PS1 variable systemwide, but if you want a specific PS1 for a single user, that's when you'd use a ~/.bashrc like GazL and upnort mentioned or ~/.profile or ~/.bash_profile.
~/.bashrc will apply to any shell, including login shells, but ~/.profile and ~/.bash_profile will only apply to login shells, and not to any subshells.
Thank you, just mention the line number (50) I was looking at this file but went unnoticed the PS1 detail
Yes, It works!.
Last edited by Nick-us; 12-11-2019 at 09:29 PM.
Reason: add info
Slackware ignores this file (/etc/bashrc), so it doesn't work!
Slackware does not ignore the file. The file does work. I have the file on all of my Slackware systems. If the file exists and the file is sourced in one of the user's bash startup files, then /etc/bashrc is used. This is how bash works in all Linux systems.
None of the bash startup files, including /etc/bashrc, exist on a stock Slackware system. Users have to create the files. When created and properly sourced the files work as expected.
The fault is not Slackware.
Quote:
just stating, ~/.bashrc
Not applicable for shell login, precisely because it is read long after user login
And yet my ~/.bashrc works in consoles and terminal windows for almost two decades.
It does not work!
I'm talking about LOGIN shell there is no graphical shell, there is no X server installed. I explained above in the question!
~/.bashrc should be run with any shell, including login shells. It seems this is not bash default, so it is not the default in Slackware. ~/.bashrc is only ran on non-login shells unless sourced elsewhere. ~/.profile and ~/.profile_bash should only be run for login shells (~/.profile_bash should be run with only bash login shells where ~/.profile should be run with any login shell).
Quote:
Originally Posted by upnort
Quote:
Slackware ignores this file (/etc/bashrc), so it doesn't work!
Slackware does not ignore the file. The file does work. I have the file on all of my Slackware systems. If the file exists and the file is sourced in one of the user's bash startup files, then /etc/bashrc is used. This is how bash works in all Linux systems.
Based on what you say, /etc/bashrc is not used by default in Slackware unless you specifically add it to be sourced somewhere, either in /etc/profile, /etc/profile.d/*, or your local files like ~/.bashrc, ~/.profile, or ~/.profile_bash, right? I didn't see any mention in man bash on using /etc/bashrc and it looks to be a local file you'd have to add support for through the existing login scripts, right?
From man bash:
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.
On Slackware (and probably other distros), /etc/profile will source files in /etc/profile.d/ with this command:
Code:
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
if [ -x $profile_script ]; then
. $profile_script
fi
done
Last edited by bassmadrigal; 12-11-2019 at 10:58 PM.
Based on what you say, /etc/bashrc is not used by default in Slackware unless you specifically add it to be sourced somewhere, either in /etc/profile, /etc/profile.d/*, or your local files like ~/.bashrc, ~/.profile, or ~/.profile_bash, right?
Right. Not used in any Linux system unless sourced somewhere, although the file is intended to be global, for all users.
Please refrain with the exclamation points.
Slackware does not ignore the file. The file does work. I have the file on all of my Slackware systems. If the file exists and the file is sourced in one of the user's bash startup files, then /etc/bashrc is used. This is how bash works in all Linux systems.
Read what you wrote? You need to write commands to another file to warn Slackware that the file exists!
So it is correct to say that Slackware ignores the file!
Because as you say it does, the file could be anywhere, have any name that of course would work.
At the moment I tell Slackware to read the example file: /mnt/dates/myfiles/trash/jonnh/mary.txt
Can I use it with a .bash just the same
Slackware Ignores file /etc/bashrc Because it is not the default of your installation. And reporting its existence is the same as installing a new program
Quote:
None of the bash startup files, including /etc/bashrc, exist on a stock Slackware system. Users have to create the files. When created and properly sourced the files work as expected.
The fault is not Slackware..
Create the file ~ /.bashrc
It is not necessary to inform the system of its existence anywhere, as the file exists only that Slackware will read its contents.
I'm not blaming Slackware I understand how it works!
Quote:
And yet my ~/.bashrc works in consoles and terminal windows for almost two decades.
You not understand the point of my question! I didn't ask how to use the .bashrc file because this I already do when I change colors and information in the terminal.
My question was how to change the information in Login Terminal on a system that does not have X Server.
I just customize /etc/profile, I want all my variables in one place, globally (on my boxes I mean, my user is THE user of the system). Yes, at the bottom there's a loop with -x condition check to run the scripts in /etc/profile.d
The user equivalent would indeed be to use ~/.bash_profile for bash login shells and you could also use ~/.profile that should apply to all shells.
The /etc/bashrc file is not actually sourced by bash. You could create a file called /etc/bananas and source it just the same.
P.S. I should also mention that I use a login shell for my terminals in X. More specifically, I've been using RXVT (now urxvt) forever and I start it with the "-ls" switch. All my terminal shortcuts are this:
Code:
urxvt -bg black -cr green -fg white -C -fn 9x15 -sl 2000 -ls
Point being, /etc/profile is appropriate for me.
Last edited by TheRealGrogan; 12-12-2019 at 01:19 AM.
It does not work!
I'm talking about LOGIN shell there is no graphical shell, there is no X server installed. I explained above in the question!
It does if you source ~/.bashrc from your ~/.bash_profile like I, and others have suggested to you in the other threads about bashrc that you've raised.
Slackware by default exports a bash specific PS1 from /etc/profile. IMO that is a mistake for a number of reasons which I've commented on in the past and wont go into again here. Suffice to say, ~/.bashrc is the appropriate place for a bash specific PS1 string to be set.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.