OS-UNIT-5
OS-UNIT-5
from users and execute them. However, sometimes we want to execute a bunch of
commands routinely, so we have to type in all commands each time in the terminal.
As a shell can also take commands as input from file, we can write these commands
in a file and can execute them in shell to avoid this repetitive work. These files are
called Shell Scripts or Shell Programs. Shell scripts are similar to the batch file in MS-
DOS. Each shell script is saved with `.sh` file extension e.g., myscript.sh.
A shell script has syntax just like any other programming language. If you have any
prior experience with any programming language like Python, C/C++ etc. It would be very
easy to get started with it.
A shell script comprises the following elements –
• Shell Keywords – if, else, break etc.
• Shell commands – cd, ls, echo, pwd, touch etc.
• Functions
• Control flow – if..then..else, case and shell loops etc.
Need of Shell Scripts: There are many reasons to write shell scripts:
• To avoid repetitive work and automation
• System admins use shell scripting for routine backups.
• System monitoring
• Adding new functionality to the shell etc.