3.1: Linux - Introduction to Shell
Introducing Shell:
- Shell is an application, works as a command interpreter
- Gets a command from user, gets it executed from OS
- Gives a programming environment to write scripts using interpreted language
- It has been inherited from UNIX operating system, which was predecessor to Linux
Type of shells:
There are two types of shells that are part of the system. Details are provided as follows:
Login shell:
- Starts after a successful login
- It is executed under user ID during login process
- It picks up user specific configuration and loads them
Non-login shell:
- A Non login shell is started by a program without a login
- In this case, the program just passes the name of the shell executable
- For example, for a Bash shell it will be simply bash
- Following are examples of Non-login shells:
o Bash
o Ksh
o Csh
Bash files:
- .bash_profile (Login shell, during login)
- .bash_logout (Login shell, during logout)
- .bashrc (Non-login shell, new instance)
- .bash_history (Non-login shell, command history)
Try out the following:
• Type echo $0 in your command prompt and see the output
• Type cat /etc/shells and understand various shells available
• Execute ls –al command
Environment Variables
- Login-shell’s responsibility is to set the non-login shell and it will set the environment variable
- Environment variables are set for every shell and generally at login time
- They are set by the system, holds special values
- Environmental variables are defined in /etc/profile, /etc/profile.d/ and ~/.bash_profile.
- When a login shell exits, bash reads ~/.bash_logout
| Environment Variable | Description |
|---|---|
| 1. SHELL | Describes the shell, that will be interpreting user commands. |
| 2. TERM | This specifies the terminal type, in which the shell is running. |
| 3. USER | The Current logged in user. |
| 4. PWD | The Current working directory. |
| 5. OLD PWD | The previous working directory. |
| 6. MAIL | The path to the current user's mailbox. |
| 7. PATH | A list of directories that the system will check when looking for commands. |
| 8. HOME | The current user's home directory. |
| 6. HOSTNAME | The hostname of the computer. |
| 7. PS1 | The primary command prompt definition |
Basic Shell Commands
| Command | Process |
|---|---|
| 1. ls | List's all the files in the current directory |
| 2. pwd | Gives present working directory. |
| 3. cd | Change directory. |
| 4. man | Gives information about command. |
| 5. exit | Exits from the Shell |
| 6. which | Shows full pather of command |
Absolute & Relative path:
- Path is the location where a particular file is located in the directory (tree) structure
- It starts with the root (‘/’) directory and goes into appropriate directory
- The path depends on the reference point from where you take it up:
1. Absolute path : Specifies the location with reference from root dir
2. Relative path : Specifies the location with reference to present working directory (pwd)
- As the name says relative path will vary depending on your pwd.
...



Post a Comment