0% found this document useful (0 votes)
42 views3 pages

Overview of Unix Shell Types and Scripting

There are two main types of shells in Unix - the Bourne shell and C shell. Shell scripts allow users to automate repetitive tasks, program features like variables and loops, and act as shortcuts for system commands. To write a shell script, the file is given a .sh extension and made executable. Common examples of shell script applications include automating code compilation, running programs, file manipulation, and backups. A basic "Hello World" shell script is also demonstrated.

Uploaded by

Rough Metal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Overview of Unix Shell Types and Scripting

There are two main types of shells in Unix - the Bourne shell and C shell. Shell scripts allow users to automate repetitive tasks, program features like variables and loops, and act as shortcuts for system commands. To write a shell script, the file is given a .sh extension and made executable. Common examples of shell script applications include automating code compilation, running programs, file manipulation, and backups. A basic "Hello World" shell script is also demonstrated.

Uploaded by

Rough Metal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Types of Shells

There are two major types of shells in Unix. These are:

Bourne Shell
This is the default shell for version 7 Unix. The character $ is the default prompt for the
bourne shell. The different subcategories in this shell are Korn shell, Bourne Again shell,
POSIX shell etc.

C Shell
This is a Unix shell and a command processor that is run in a text window. The character
% is the default prompt for the C shell. File commands can also be read easily by the C
shell, which is known as a script.

Capabilities of Shell Script


The different capabilities of the shell script are −

 Batch jobs

o Several commands that would be entered manually in a command line


interface can be executed automatically using a shell script. This can be done
without the user needing to trigger each command separately.

 Programming

o There are many features in modern shell scripts that are only found in
sophisticated programming languages such as arrays, variables, comments
etc. Many complicated applications can be written in shell scripts using these
features. But there is a problem i.e. shell script languages don’t support
classes, threading etc.

 Generalization

o It is much more flexible to use loops, variables etc for multiple tasks in shell
script. An example of this is a Unix shell script known as bash, which converts
jpg images to png images.

 Shortcuts
o There is a shortcut provided by a shell script for a system command where
command options, environment settings or post processing apply. This still
allows the shortcut script to act as a Unix command.

Shell Scripting She-bang


The sign #! is called she-bang and is written at top of the script. It passes instruction to
program /bin/sh.

To run your script in a certain shell (shell should be supported by your system), start
your script with #! followed by the shell name.

Example:

1. #!/bin/bash
2. echo Hello World

Steps to write and execute a script


 Open the terminal. Go to the directory where you want to create your script.
 Create a file with .sh extension.
 Write the script in the file using an editor.
 Make the script executable with command chmod +x <fileName>.
 Run the script using ./<fileName>.

Examples of shell script applications


Using a shell script is most useful for repetitive tasks that may be time consuming to
execute by typing one line at a time. A few examples of applications shell scripts can be
used for include:

 Automating the code compiling process.


 Running a program or creating a program environment.
 Completing batch
 Manipulating files.
 Linking existing programs together.
 Executing routine backups.
 Monitoring a system.

# Hello World Program in Bash Shell

echo "Hello"

echo $SHELL

var1=9

pwd

ls -l

if [ "$var1" -ge 10 ]; then

echo "Bigger Number"

else

echo "smaller number"

fi

Common questions

Powered by AI

Shell scripts are particularly useful for repetitive tasks that need to be automated. Examples include automating code compilation, setting up program environments, managing batch processes, file manipulation, linking existing programs, executing system backups, and monitoring system status. These tasks benefit from shell scripting as they often involve sequences of commands that need consistent execution.

Bourne Shell is the default shell for version 7 Unix and uses the character '$' as the default prompt. C Shell, on the other hand, is a Unix shell and command processor that runs in a text window and uses the character '%' as the default prompt.

Shell scripts enable generalization by utilizing loops, variables, and other flexible constructs to handle multiple tasks efficiently. For example, a shell script can automate the conversion of jpg images to png images through a loop that processes every file in a directory. Such generalization is useful in scenarios where repetitive operations apply to different data sets.

Modern shell scripts can use sophisticated programming features such as arrays, variables, and comments, enabling developers to write complex applications. However, shell scripting languages usually do not support features like classes and threading, which are typical in full-fledged programming languages. This limits the complexity of applications that can be efficiently developed with shell scripts.

The 'she-bang' is represented by the combination #! at the beginning of a script. It indicates the script interpreter's path to the system and directs the shell to execute the script using the specified interpreter. This ensures the script runs in the intended environment, which is essential for scripts relying on specific shell features.

Shell scripts are used to monitor systems because they can automate the checking of system health parameters like disk usage, process statuses, and system load. They simplify system administration by providing automated alerts and logs, reducing the manual oversight required and facilitating proactive issue management.

Shell scripts can enhance system commands by providing shortcuts where specific command options, environment settings, or post-processing steps apply. These shortcuts allow commands to be executed more efficiently while maintaining the flexibility and functionality of full command execution. Benefits include time savings, reduced complexity for users, and consistent application of required parameters and settings.

Shell scripts facilitate linking existing programs by serving as intermediaries that can execute multiple programs in sequence or parallel, handling the output and input between them effectively. Advantages include streamlined workflows, reduced manual intervention, and the ability to integrate various tools and applications seamlessly.

Shell scripting allows automation of tasks by executing multiple commands automatically, rather than requiring manual entry of each command individually. This is beneficial for time-consuming and repetitive tasks, making it preferred over manual command entry as it reduces human error and saves time.

To write and execute a shell script in Unix: 1. Open the terminal and navigate to the desired directory. 2. Create a file with the .sh extension. 3. Write the script using an editor. 4. Make the script executable with the command chmod +x <fileName>. 5. Run the script using ./<fileName>. This process ensures the script is correctly authored and secure for execution.

You might also like