Shell Customising Your Shell
Customising your shell means changing its settings to suit you. The settings live in a startup file that the shell reads when it starts.
Set a short prompt
PS1 sets the prompt. echo shows the new prompt text.
PS1='my-shell$ '
echo "$PS1"Save it in .bashrc
.bashrc runs when bash starts. Save the setting there.
printf 'PS1="my-shell$ "\n' > home/.bashrc
cat home/.bashrcLoad the file now
source reads a file into the current shell. The new prompt takes effect at once.
printf 'PS1="my-shell$ "\n' > home/.bashrc
source home/.bashrc
echo "$PS1"The zsh twin
.zshrc is the file zsh reads. The same setting works there.
printf 'PS1="my-zsh$ "\n' > home/.zshrc
source home/.zshrc
print "$PS1"Example
printf 'PS1="my-shell$ "\nalias ll="ls -l"\n' > home/.bashrc
source home/.bashrc
echo "$PS1"
alias llKey points
- .bashrc: the file that bash reads when a new interactive shell starts.
- .zshrc: the file that zsh reads, the twin of .bashrc.
- PS1: the variable that sets the prompt.
- Use source to read a startup file into the current shell.
- A change to .bashrc needs a new shell or source before it takes effect.
In this example, .bashrc gets a prompt and an alias. source loads the file, so the new prompt prints and the alias is listed.
Note
Keep startup files short, so a new shell starts fast.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
When does bash read .bashrc?