Background
The good thing about personal computing is that it lends itself to quick and easy customizing.
In this post, we will cover how we can use “login scripts” to customize our prompt while in Linux’s terminal mode.
OSes
Microsoft – Win OS
In the Microsoft Windows world, one can use autoexec.bat to run scripts when the computer starts up.
BTW, autoexec stands for “auto execution”.
As Microsoft graduated into a unified directory system, Active Directory, one can set the logon script for each AD User.
Or use Group Policy ( GP ).
Linux
File Name Structure
Depending on the shell type and the intended user scope, the file name that we will need to modify will be slightly different.
Folder Names
Scope | Folder |
---|---|
User | ~/ |
Root | /root |
Global (All users except root) | /etc |
File Names
Shell | Scope | Filename | Folder |
---|---|---|---|
Bash | |||
User | ~/.bash_profile | ||
Global (All users except root) | /etc/profile.d | ||
Root | /root/.bash_profile | ||
Bourne or Korn shell | |||
User | ~/.profile | ||
C shell ( csh ) | |||
User | ~/.login |
Customization
Terminal Mode – Prompt
WSL
Here is the default terminal’s prompt on my WSL:-
Output – Image
Output – Textual
dadeniji@M2:/mnt/c/WINDOWS/system32$
Explanation
Here is a quick breakdown of the default prompt
- user
- username
- @
- computer
- computer-name
- :
- Current Folder
- /mnt/c/windows/system32$
Customize
Let us quickly reduce the clutter a bit.
Outline
- File
- File name:- ~/.bash_profile
- File Content
- export PS1=’>’
- File Mode
- mark file as executable
- chmod +x <filename>
- mark file as executable
- Execute File
File Name
My current default shell is bash.
The change is for only me.
And, so the filename is ~/.bash_profile.
File Content
vi’ed file
File Mode
Using chmod marked file as executable.
chmod +x ~/.bash_profile
Execute File
Using the source command try to execute our little file ( /home/$USER/.bash_profile ).
source ~/.bash_profile
Lab
As always take it to the lab, add a bit more complexity.
In our case, we added our salutation script.
Source Code
Textual
export PS1='>' source "/home/$USER/script/bash/salutation.sh"
Image
Output
Image
The next time we log on to the system, here is what we see
Explanation
- dadeniji, Good morning
- username
- Time of Day
- Prompt
- >
Referenced Work
- hello world in bash
Link