https://github.com/krushna-prasad-sahoo/shell-script-practice
https://github.com/krushna-prasad-sahoo/shell-script-practice
bash linux shell
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/krushna-prasad-sahoo/shell-script-practice
- Owner: Krushna-Prasad-Sahoo
- Created: 2022-03-16T18:35:33.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T11:59:09.000Z (about 2 years ago)
- Last Synced: 2025-03-25T11:49:16.389Z (over 1 year ago)
- Topics: bash, linux, shell
- Language: Shell
- Homepage:
- Size: 88.9 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Know Your Environment
Kernel ?
- An intermediate program
- Interface between hardware & software
Shell?
- An interface between users & Kernel/OS
- `cat /etc/shells` : check which all shell programs are available in your OS
- `echo $0` : check your current shell
- `cat /etc/passwd` : check which user is associated with which shell
Shell Types ?
- Graphical Shells
- Gnome
- KDE
- CLI Shells
- sh (bourne shell)
- bash (bourne again shell)
- csh & tcsh
- ksh (korn shell - solaris)
Shell Scripting ?
- Put all instructions in a specific file & RUN it on Shell
- Give file extension as `.sh` (not mandatory)
Run a Shell Script ?
- Absolute path (example - `/home/student/scripts/testing.sh`)
- Reletive path (example - `./testing.sh`, when you are already present at `/home/student/scripts/` directory)
### Scripting Best Practices
- Script File Convention :
- make a work directory & keep scripts in it.
- script name should identify function/operation
- extension can be given as .bash/.csh/.ksh if working in multiple shells.
- Script File Permission :
- chmod a+x name (make executable)
- Shell Script Format :
- Define Shell (#!/bin/bash)
- Comments (# comments)
- Define Variables
- Commands
- Statements (include indentation)
- Script is executed from top to bottom in sequence.
- Add Exit/Status Code in your code :
- If code is `0` : Code executed successfully
- Else if code is `1-255` : Code execution was not successful.

