Ubuntu Tutorial

Shell : Shell is command line interpreter that executes user commands OR a shell is a program that provides an interface between a user and an operating system (OS) kernel. There are many type of shell example Bash Shell , Tcsh/csh Shell , Ksh Shell, Zsh Shell. But among this Bash (Bourne Again Shell) is used in many Linux distributions. When we use bash, we get $ in terminal path.

When shell gets command, it identifies command name, arguments and options. When command is sent to the execution the arguments and options are passed to the command. Now the shell gets into inactive state and waits for signal (exit or end of task). After getting response from command shell forward this response directly to the terminal. at the end terminal print response.

Special characters : shell has separate meaning to special charcter. be careful when using special character into command. Following are some example for special character. !! : This represent previously executed command. in following example first we execute ls command on terminal then we execute !! -l here !! represent ls (previously executed command) command so shell execute ls -l command.

Image
!! command

Types of shells:

  • Login shell : A login shell logs you into the system as a specified user, it is necessary to enter username and password.
  • Non-login shell : A shell that is executed without logging in. it logs you into the system as a currently logged-in user. example gnome-terminal
  • Interactive shell : A shell (login or non-login) where you can interactively type or interrupt commands. For example a gnome-terminal.
  • Non-interactive shell : A (sub) shell that is probably run from an automated process. You will see neither input nor output.

cat /etc/shells command will print to shells that are already installed.

Image
cat etc shells command

echo $0 will print name of running shell.

Image
echo $0

chsh -s shellname command is used to switch between shells. type shell name in place of shell name.

Customizing the Shell prompt : Following commands changes the default terminal path and effect of command vanishes after closing terminal.

if terminal path is "ubuntu@ubuntu-inspiron-3542:~/Videos$"

Command Description Terminal Path
PS1='\w $ ' Set terminal path as path + space + $ + space here \w refer as working directory. ~/Videos $
PS1='\h $' Set terminal path as host/device name + space + $ here \h refer as host name ubuntu-inspiron-3542 $
PS1='\u $ ' Set terminal path as user name + space + $ + space here \u refer as user name ubuntu $
PS1='\t $ ' Set terminal path as time(24 hour format) + space + $ + space here \t refer as time 17:20:26 $
PS1='\@ $ ' Set terminal path as time(12 hour format) + space + $ + space here \@ refer as time with AM/PM 5:24 PM $
PS1='\! $ ' Set terminal path as history number of command + space + $ + space here \! refer as history number command 1701 $
PS1='fun $ ' Set terminal path as given string( here fun) + space + $ + space fun $