Bourne Shell (sh)
History
The Bourne Shell (sh) was developed by Stephen Bourne at AT&T Bell Laboratories and released in 1979 as the default Unix shell in Version 7 Unix. It was designed to be a command interpreter and scripting language, providing a way to automate tasks and manage system operations. The Bourne Shell has influenced many other shells, including the Korn Shell (ksh) and the Bourne Again Shell (bash).
Features
Scripting: Supports writing scripts to automate tasks.
Command Substitution: Allows the output of a command to replace the command itself.
Control Structures: Provides constructs for conditional execution and loops.
Variables: Supports the use of variables to store data.
Redirection: Allows input and output redirection for commands.
Pipelines: Supports chaining commands together using pipes.
Basic Commands
Navigation
pwd
: Print the current working directory.cd [directory]
: Change the current directory to the specified directory.ls
: List the contents of the current directory.
File and Directory Management
touch [filename]
: Create a new empty file.mkdir [directory]
: Create a new directory.rm [filename]
: Remove a file.rmdir [directory]
: Remove an empty directory.cp [source] [destination]
: Copy a file or directory.mv [source] [destination]
: Move or rename a file or directory.
Scripting
Basic Script
Variables
Conditional Statements
Loops
For Loop
While Loop
Functions
File Operations
Creating a File
Reading a File
Deleting a File
Example: Backup Script
This script compresses the contents of the source directory into a tar.gz file and saves it in the backup directory with a timestamp.