0% found this document useful (0 votes)
12 views5 pages

Expt 2 - COS - 008

The document outlines an experiment for a Computer Operating System course focused on shell programming and system calls. It includes objectives, implementation details for various shell scripts, and questions regarding shell types and their advantages and disadvantages. The conclusion emphasizes the completion of the study on shell scripting.

Uploaded by

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

Expt 2 - COS - 008

The document outlines an experiment for a Computer Operating System course focused on shell programming and system calls. It includes objectives, implementation details for various shell scripts, and questions regarding shell types and their advantages and disadvantages. The conclusion emphasizes the completion of the study on shell scripting.

Uploaded by

jossilwhatsapp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

K. J.

Somaiya College of Engineering, Mumbai-77


(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering

Course Name: Computer Operating System (Elective) Semester: VII


Date of Performance: 15 / 8 / 2024 Batch No: A1
Faculty Name: Prof Nilesh Lakade Roll No: 16010221008
Faculty Sign & Date: Grade/Marks: / 25

Expt No: 2
Title: Shell Programming and system calls.

Aim and Objective of the Experiment:


 To study the shell script and write the program using shell.

COs to be achieved:
CO 1: Explain the fundamental concepts of operating system
CO5: Explain basic features of Unix and Mobile OS.

Theory:

The shell provides you with an interface to the UNIX system. It gathers input from you and executes
programs based on that input. When a program finishes executing, it displays that program's output.

Shell Scripts
The basic concept of a shell script is a list of commands, which are listed in the order of execution. A
good shell script will have comments, preceded by a pound sign, #, describing the steps.

Steps to create a Shell Script:


create a file using any text editor say vi, gedit, nano etc.
1.$ vi filename
2.Insert the script/ commands in file and save the file to execute the file we need to give execute
permission to the file
3.$ chmod 775 filename
4.Now execute the above file using any of following methods:
$ sh filename
OR
$ ./filename

NOTE: Before adding anything to your script, you need to alert the system that a shell script is being
started. This is done using the shebang construct. For example −
#!/bin/sh.

Computer Operating System Semester: VII Academic Year: 2024-25


Roll No:
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering

Description of the application to be implemented:


1. Write a shell Script that accepts two file names as command line arguments and compare two file
contents and check whether contents are same or not. If they are same, then delete second file.

2. Write a shell script that accepts integer and find the factorial of the number.

3. Write a shell script for adding users.

4. Write a shell script for counting no of logged in users.

5. Write a shell script for counting no of processes running on system

Implementation details/Circuit Diagram/ Block Diagram:

Program for System Call:


1. Write a Program for creating process using System call (E.g fork()) Create a child
process. Display the details about that process using getpid and getppid functions. In a child
process, Open the file using file system calls and read the contents and display.

Implementation details: (printout of code / screen shot)

Computer Operating System Semester: VII Academic Year: 2024-25


Roll No:
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering

Post Lab Subjective/Objective type Questions:


1. What are the different types of commonly used shells on a typical linux system?

On a typical Linux system, several shells are commonly used. Bash (Bourne Again Shell) is the
most widely used, providing features like advanced scripting capabilities, command history, and job
control. It is the default shell on many distributions due to its extensive functionality. Sh (Bourne
Shell) is one of the oldest Unix shells known for its simplicity and portability, often serving as a
standard for basic scripting and compatibility. Dash (Debian Almquist Shell) is a lightweight,
POSIX-compliant shell optimized for speed and efficiency, commonly used as `/bin/sh` on Debian-
based systems. Zsh (Z Shell) is favored for its advanced features, including improved tab completion
and a customizable prompt, making it popular among power users. Ksh (Korn Shell) offers
advanced scripting capabilities, including built-in floating-point arithmetic and associative arrays,

Computer Operating System Semester: VII Academic Year: 2024-25


Roll No:
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering

useful for complex scripting needs. Tcsh (Tenex C Shell) enhances the C shell (`csh`) with features
like command-line editing and filename completion, preferred by users of C shell syntax. Fish
(Friendly Interactive Shell) emphasizes user-friendliness with features like syntax highlighting and
autosuggestions, appealing to those who prioritize an intuitive interactive experience.

2. How do you find out what’s your shell?

To find out which shell you are currently using on a Linux system, you can use
several methods:
1. `echo $SHELL`: This command prints the path of the current shell as specified
in your user account settings. For example, it might output `/bin/bash` or
`/usr/bin/zsh`.
2. `ps -p $$`: This command shows information about the process with the ID of
your current shell. The output will include the shell’s name. For example, it might
show `bash` or `zsh` as the command associated with the shell process.
3. `echo $0`: In some cases, this command can display the name of the shell used to
invoke the current script or session. However, it might not always reflect the
current interactive shell.
4. `cat /etc/passwd`: You can look at your user entry in the `/etc/passwd` file. Find
your username and check the last field, which shows the default shell for your
account. For example, it might show `/bin/bash` or `/usr/bin/zsh`.
Each of these methods provides information about the shell you are currently using
or the default shell configured for your user account.

3. List the advantages and disadvantages of shell scripting.

Shell scripting offers a variety of advantages and disadvantages, making it suitable for certain tasks
while less ideal for others.
One major advantage of shell scripting is its simplicity and ease of use. Shell scripts are typically
written in plain text and can be executed directly in a terminal, making them accessible for
automating routine tasks and system administration. They provide a straightforward way to combine
and automate command-line operations, making repetitive tasks more efficient. Additionally, shell
scripts are highly portable and can run on any Unix-like system, including Linux and macOS,
without needing modifications. This makes them an excellent choice for cross-platform automation
tasks.
However, there are notable disadvantages to shell scripting as well. Shell scripts can become
difficult to manage and debug, especially when they grow in complexity. The lack of advanced error
handling and debugging tools can make troubleshooting challenging. Furthermore, shell scripting
often lacks the robustness and performance of compiled programming languages, which can be a
limitation for more complex or performance-sensitive tasks. Security concerns are also relevant, as
shell scripts can be prone to issues like command injection if not written with care. This requires
careful scripting practices to ensure that scripts do not inadvertently expose systems to security
vulnerabilities. In summary, while shell scripting provides a simple and effective way to automate
tasks and manage system operations, it may not be suitable for all scenarios, especially those
requiring advanced error handling, performance optimization, or robust security measures.

Computer Operating System Semester: VII Academic Year: 2024-25


Roll No:
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering

Conclusion:

Thus, we have completed the study of the shell script and written the program using shell.

Signature of faculty in-charge with Date:

Computer Operating System Semester: VII Academic Year: 2024-25


Roll No:

You might also like