LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-11-2019, 06:06 PM   #1
Nick-us
Member
 
Registered: Feb 2019
Distribution: Slackware64-Current
Posts: 65

Rep: Reputation: 8
Question Customizing the login shell, It's possible?


In google, they only talk about the graphical shell. Never talk about base shell, initial shell.

I would like to customize it.

The only thing I learned to do is change hostname, msg
etc/HOSTNAME
etc/issue

But I would like to do the same thing I do in the graphical shell

Code:
if [ `id -un` = root ]; then
   PS1="\[\e[100m\]\w\n\[\e[1;41m\]\\$\[\e[0m\] "
else
   PS1="\[\e[100m\]\w\n\[\e[1;46m\]\\$\[\e[0m\] "
fi
It is possible? And if possible, where can I put this code above so that it can be read when logging in?
 
Old 12-11-2019, 06:51 PM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,896

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Setting PS1 is best done in ~/.bashrc
 
Old 12-11-2019, 06:56 PM   #3
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Rep: Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161
If wanting the changes global for all users, /etc/bashrc. As GazL mentioned, users can override that in $HOME/.bashrc.
 
Old 12-11-2019, 07:35 PM   #4
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by upnort View Post
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.
 
1 members found this post helpful.
Old 12-11-2019, 09:10 PM   #5
Nick-us
Member
 
Registered: Feb 2019
Distribution: Slackware64-Current
Posts: 65

Original Poster
Rep: Reputation: 8
Quote:
Originally Posted by GazL View Post
Setting PS1 is best done in ~/.bashrc
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!
 
Old 12-11-2019, 09:11 PM   #6
Nick-us
Member
 
Registered: Feb 2019
Distribution: Slackware64-Current
Posts: 65

Original Poster
Rep: Reputation: 8
Quote:
Originally Posted by upnort View Post
If wanting the changes global for all users, /etc/bashrc. As GazL mentioned, users can override that in $HOME/.bashrc.
Slackware ignores this file (/etc/bashrc), so it doesn't work!
 
Old 12-11-2019, 09:15 PM   #7
Nick-us
Member
 
Registered: Feb 2019
Distribution: Slackware64-Current
Posts: 65

Original Poster
Rep: Reputation: 8
Thumbs up

Quote:
Originally Posted by bassmadrigal View Post
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
 
Old 12-11-2019, 09:28 PM   #8
Nick-us
Member
 
Registered: Feb 2019
Distribution: Slackware64-Current
Posts: 65

Original Poster
Rep: Reputation: 8
Quote:
Originally Posted by bassmadrigal View Post
~/.bashrc will apply to any shell, including login shells,
just stating, ~/.bashrc
Not applicable for shell login, precisely because it is read long after user login
 
Old 12-11-2019, 09:47 PM   #9
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Rep: Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161
Please refrain with the exclamation points.

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.

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.

Please refer to Bash Startup Files for how the files are sourced.
 
1 members found this post helpful.
Old 12-11-2019, 10:30 PM   #10
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by Nick-us View Post
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 View Post
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.
 
Old 12-12-2019, 12:02 AM   #11
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Rep: Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161
Quote:
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.
 
Old 12-12-2019, 12:05 AM   #12
Nick-us
Member
 
Registered: Feb 2019
Distribution: Slackware64-Current
Posts: 65

Original Poster
Rep: Reputation: 8
Quote:
Originally Posted by upnort View Post
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.

Please refer to Bash Startup Files for how the files are sourced.
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.

Last edited by Nick-us; 12-12-2019 at 12:21 AM.
 
Old 12-12-2019, 12:43 AM   #13
TheRealGrogan
Member
 
Registered: Oct 2010
Location: Ontario, Canada
Distribution: Slackware, LFS, Manjaro (for gaming)
Posts: 570

Rep: Reputation: 413Reputation: 413Reputation: 413Reputation: 413Reputation: 413
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.
 
1 members found this post helpful.
Old 12-12-2019, 02:00 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,791

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
I would suggest you to read man bash, especially the section INVOCATION, where it is explained very well.
 
1 members found this post helpful.
Old 12-12-2019, 04:01 AM   #15
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,896

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Quote:
Originally Posted by Nick-us View Post
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.
 
1 members found this post helpful.
  


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
[SOLVED] on: customizing root's shell prompt textillis Slackware 14 07-23-2013 05:40 AM
Login Shell / Non-Login shell Clarification needed (RHEL 6.3) kingston Linux - Newbie 1 12-07-2012 12:51 AM
Animating and Customizing the Shell Konsole? oktet Linux - General 2 08-02-2008 02:34 AM
Customizing KDE login jdozarchuk SUSE / openSUSE 3 02-07-2005 08:39 PM
Customizing the GUI login screen Wynand1 VectorLinux 3 03-04-2004 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

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