In this section, we will take a look at different types of shells.
To check the shell being used. Use the command echo $SHELL
$ echo $SHELL
To change the default shell. Use the command chsh, you will be prompted for the password and following that input the name of the new shell. You have to login into new terminal session to see this change though.
$ chsh
Bash supports command auto-completion. What this means is bash means to auto-complete commands for you if you type part of it and press the tab key
$ date
$ alias dt=date
$ dt
history command to list the previous run commands that you ran earlier
$ history
## Bash environment variables
To print SHELL environment variable
$ echo $SHELL
To see a list of all environment variables. Run env from the terminal
$ env
To set an environment variable with in the shell. The value is not carry forward to any other process.
$ OFFICE=bob
To set an environment variable we can use the export command. To make the value carry forward to any other process.
$ export OFFICE=bob
To persistently set an environment variable over subsequent login or a reboot add them to the ~/.profile or ~/.pam_environment in the users home directory.
$ echo "export OFFICE=bob" >> ~/.profile (or)
$ echo "export OFFICE=bob" >> ~/.pam_environment
To check the value of a environment variable called LOGNAME
$ echo $LOGNAME
To see the directories defined in path variable. Use the command echo $PATH.
$ echo $PATH
To check if the location of the command can be identified. Use the which command
Syntax: which <command>
$ which obs-studio
To define a command in the PATH variable. To add we can use the export command.
$ export PATH=$PATH:/opt/obs/bin
$ which obs-studio
Once you login into the shell, the line you see is the bash prompt.
It can be customized to see the username and the hostname
PS1 variable.To see the value assign to PS1, type echo $PS1
$ echo $PS1
To change the PS1 to only display the word ubuntu-server.
$ PS1="ubuntu-server"
$ echo $PS1
To change the bash prompt to display date, time, username of the current user, the hostname and the current working directory
$ PS1="[\d \t \u@\h:\w ] $ "