0% found this document useful (0 votes)
9 views2 pages

Shell Programming Lab Assignment Guide

The document outlines a lab assignment focused on shell programming in Linux, requiring the creation of scripts for arithmetic operations and file management. It includes objectives such as creating directories, manipulating files, and understanding Linux shell commands. Additionally, it provides FAQs and a conclusion emphasizing the versatility of the Linux shell for various operations.

Uploaded by

shrees
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)
9 views2 pages

Shell Programming Lab Assignment Guide

The document outlines a lab assignment focused on shell programming in Linux, requiring the creation of scripts for arithmetic operations and file management. It includes objectives such as creating directories, manipulating files, and understanding Linux shell commands. Additionally, it provides FAQs and a conclusion emphasizing the versatility of the Linux shell for various operations.

Uploaded by

shrees
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

Lab Assignment 1

Title: Shell Programming in Linux

Problem statement:

1.​ Write a Shell script to perform Arithmetic operations.


2.​ Write a Shell script to manage Files and Directory

Objective:

1.​ Write a Menu driven shell script to perform addition, subtraction, Multiplication and
Division operators.
2.​ A directory contains several files and subdirectories. Write a command or script to:

●​ Create a directory and subdirectory.


●​ Create a .txt file using cat command
●​ Make a copy of it, rename it
●​ Set read/write/execute for owner and read-only for group/others
●​ List all files in the directory with owner, group and others rights.

Objectives:

Understanding of Linux shell commands & shell programming

Theory:

Linux Shells, Types of shells, Shell scripting, applications, example

Input: please specify input test case

Output: please specify the expected output for the input test case

FAQS:
1. What is the significance of the shebang (#!) at the beginning of a shell script? Explain with
the example of #!/bin/sh.
2. Write a script to back up all .txt files from the current directory into a new directory named
backup and compress it.
3. Write a shell script to generate the Fibonacci sequence up to 10.

4. Compare Shell script with any other script that automates tasks, controls systems, or
manipulate files

Conclusion:

The Linux shell provides several commands and programming language constructs to
implement various operations.

Common questions

Powered by AI

Setting file permissions using shell scripts involves using the 'chmod' command to specify read, write, and execute rights for the owner, group, and others. A script can automate this by using 'chmod' with symbolic or numeric permissions, enabling consistent and secure permission settings across multiple files. This ensures unauthorized users cannot alter sensitive files, maintaining system integrity and security .

Key theoretical knowledge includes understanding different shell types, command syntax, I/O redirection, and scripting constructs like loops, conditionals, and variables. Awareness of command-line utilities and their options, along with process management and script execution environment, is crucial. This foundational understanding allows script developers to effectively utilize the shell's capabilities to automate and control tasks .

To back up all .txt files in the current directory, the script must first check for an existing 'backup' directory or create it. It then copies the .txt files into this directory using 'cp'. After ensuring that the files are transferred, the script compresses the 'backup' directory using tools like 'tar' or 'zip'. This automation simplifies regular backups and ensures the integrity of files .

Using shell scripting to list files with detailed permissions allows administrators to quickly assess and audit access rights across files and directories. This provides clear insight into who can read, write, or execute files, enabling better security management and compliance checks. It also allows batch reporting on permission settings, saving time compared to manual inspection .

The shebang (#!) at the beginning of a shell script specifies the path to the interpreter that should be used to execute the script. For example, #!/bin/sh tells the system to use the sh shell interpreter to run the script. This ensures that the script runs in the specified environment, and it affects execution by configuring the script to use specific shell features and syntax based on the interpreter .

Generating a Fibonacci sequence in a shell script involves initializing two variables with the first two numbers, then iteratively calculating the next number by adding the previous two. This process continues within a loop until reaching the desired length, typically controlled by a counter. Computationally, shell scripts handle small sequences efficiently, but performance may degrade with larger sequences due to the shell's scripting limitations and lack of advanced numeric handling .

Shell scripts enhance file management by automating tasks like creating directories and files, setting permissions, and organizing files. For instance, a script can create a directory structure using 'mkdir' commands, generate files with 'cat', and automate the renaming or copying of files using 'cp' or 'mv'. Scripts can also set precise permissions using 'chmod', ensuring efficient and repeatable file management on systems .

A shell script can be written with a menu-driven interface to allow users to input numbers and choose the arithmetic operation (addition, subtraction, multiplication, division) they want to perform. This involves prompting the user for inputs, using shell scripting variables to store those inputs, and then applying the respective arithmetic operators within the script to calculate and display the result .

Creating a recursive directory structure via shell scripting facilitates organization in software development by automatically generating the necessary directories for source code, libraries, and build scripts. This creates a standardized environment conducive to version control and collaborative development. It ensures that all team members use consistent directory layouts, improving workflow efficiency and reducing human error in directory setup .

Shell scripts excel in task automation due to their close integration with the Unix/Linux command line, allowing direct execution of shell commands and utilities. They streamline routine tasks like file manipulation and process management. In contrast, other scripting languages like Python or Perl offer more advanced programming constructs, extensive libraries, and are cross-platform, making them suitable for complex applications beyond task automation. However, shell scripts are often more efficient for system-level scripting tasks due to their lightweight nature and direct access to system processes .

You might also like