0% found this document useful (0 votes)
11 views4 pages

Lab Assignment 5WedFri - Introduction To Shell

Uploaded by

JATIN HAJARE
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)
11 views4 pages

Lab Assignment 5WedFri - Introduction To Shell

Uploaded by

JATIN HAJARE
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

School of Computer Science Engineering and Technology

Bennett University (The Times Group)

Program- BTech-3rd Semester Type- Sp. Core-I


Course Code- CSET213 Course Name-Linux and Shell Programming
Year- 2025 Semester- Odd
Date- 22/08/2025 Batch- Cyber Security (B75-86)

Lab Assignment 5
Exp Name CLO Achieved Marks
No CO1 CO2 CO3 CO4
5 Introduction to Shell, Shell basic commands, √ √ 2
variables
Objective: To understand file permissions, external & bult-in Linux commands, and environment
variables using shell commands
Outcomes: After hands-on you will be able to understand basic layout of a shell program and write
basic shell scripts.
Hands-on Learning (60 minutes)
How to Write a Shell Script?
Write a script → Make the script executable → Put the script somewhere the shell can find it

Understanding Linux File Permissions (30 minutes)


Command Syntax Work
chmod $ chmod g+w Changing the permissions on files and directories
filename
$ chmod g-wx
filename

$ chmod o+w
filename

$ chmod o-rwx
foldername

$ chmod ugo+rwx to give read, write, and execute to everyone.


foldername

$ chmod a=r to give only read permission for everyone.


foldername
$ chmod 777 Change Permissions in Numeric Code instead of “r”,
foldername “w”, or “x”.

0= No Permission,

1 = Execute

2 = Write
School of Computer Science Engineering and Technology
Bennett University (The Times Group)
4 = Read

Permission numbers are:

0 = ---

1 = --x

2 = -w-

3 = -wx

4 = r-

5 = r-x

6 = rw-

7 = rwx

chgrp $ chgrp groupname Change Groups of Files and Directories


filename

$ chgrp groupname
foldername

chown $ chown name filename changing ownerships of files and directories

$ chown name
foldername

Introduction to Shell Programming


✓ Shell program is a logical sequence of Linux commands to solve a problem.
✓ Shell script can take input from user, file and output them on screen, file.
✓ Useful to create our own commands that can save our lots of time and to automate some tasks
of day today life.

Variables in Shell Script


✓ Sometimes to process our data/information, it must be kept in computers RAM memory.
✓ RAM memory is divided into small locations, and each location had unique number called
memory location/address, which is used to hold our data.
School of Computer Science Engineering and Technology
Bennett University (The Times Group)
✓ Programmer can give a unique name to this memory location/address called memory variable
or variable (Its a named storage location that may take different values, but only one at a time).
✓ In Shell, there are two types of variables:
o System variables - Created and maintained by Linux itself. This type of variable
defined in CAPITAL LETTERS.
o User defined variables (UDV) - Created and maintained by user. This type of variable
defined in lower LETTERS.
✓ Reading variables from a user input using read command
o read [options] var1 var2 … varN

o
School of Computer Science Engineering and Technology
Bennett University (The Times Group)
External commands Vs Built-in commands (10 minutes)
For external commands a child process is forked, while
built-in commands are part of the shell’s toolkit.
Environment Variables (10 minutes)
– These allow us to customize our LINUX environment
$ setenv Dog Goofy

$ printenv, $ printenv HOME, $ echo $HOME, $ ls $HOME, $ ls /home/vimal, $ set

User Defined Variables:


$ echo $my_variable, $ my_variable=Hello, $ echo $my_variable

Problems to be solved (40 minutes)


1. A file state.txt has current permissions as 643. Write a shell script to change permissions of a
file state.txt with current permissions that allows the owner with full permissions, group has
read and execute permissions and others can read the file state.txt. (Odd Batch)
2. Write a script that displays a simple status report of the system, including the current date/time,
the currently logged-in users, and the system's uptime. (Odd Batch)
3. Write a shell script that displays “man”,”bear”,”pig”,”dog”,”cat”,and “sheep” on the screen
with each appearing on a separate line. Try to do this in as few lines as possible. (Even Batch)
4. Write a script that uses a for loop to print numbers from 1 to 10. (Even Batch)
5. Write a shell program to convert all lowercase letters in a file to uppercase letter. (Both)
6. Read the marks of 10 students for LSP course in terms of Name, regID, and Marks and redirect
in a file. (Both)
7. Write a script that asks the user for a directory name and then checks if that directory exists. It
should print a different message depending on whether the directory is found or not (Both)
Submission Instructions:
1. Submission requires the screen shots of all the incurred steps to execute a shell script or a video
showing the whole process.
2. All these files are in single zip folder.
3. Use the naming convention: Prog_CourseCode_RollNo_LabNo.docx (Example:
BCA3rdSem_CBCA221_ E21BCA002_Lab1.1)
4. Submission is through LMS only

You might also like