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

Shell Scripts: User Info, File Ops, Math

The document outlines an assignment focused on creating and executing shell scripts using basic UNIX/Linux commands. It includes three parts: displaying system and user information, performing file and directory operations, and executing simple arithmetic operations. Each part provides specific instructions, code examples, and highlights the learning outcomes related to Linux command usage and scripting techniques.

Uploaded by

z.i.an.378.5.5
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)
39 views4 pages

Shell Scripts: User Info, File Ops, Math

The document outlines an assignment focused on creating and executing shell scripts using basic UNIX/Linux commands. It includes three parts: displaying system and user information, performing file and directory operations, and executing simple arithmetic operations. Each part provides specific instructions, code examples, and highlights the learning outcomes related to Linux command usage and scripting techniques.

Uploaded by

z.i.an.378.5.5
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

Assignment 3 – Shell Scripts Using Simple Commands

Topic: Write and execute shell scripts using simple UNIX/Linux commands

Part A – Display System and User Information (3 Marks)

File Name: [Link]

Instructions:
1. Create a script that displays:
- Current username
- Current date and time
- Current working directory
- List of files in current directory
2. Use suitable Linux commands (whoami, date, pwd, ls).

Code:-

echo “User Name: $(whoami)”

echo “Date and Time : $(date)”

echo “Current Directory: $(pwd)”

echo “Files:”

ls

Code Output:-
Assignment 3 – Shell Scripts Using Simple Commands

Part B – File and Directory Operations (3 Marks)

File Name: [Link]

Instructions:
1. Create a script that:
- Asks the user for a folder name
- Creates the folder
- Navigates into it
- Creates three text files
- Displays the list of created files
2. Use commands: mkdir, cd, touch, ls, echo.

Code:-

Echo –n “Enter folder Name:”

mkdir $folder name

cd $folder name

touch [Link] [Link] [Link]

echo “Files created.”

ls

Code Output:-

Part C – Simple Arithmetic Operations (4 Marks)


Assignment 3 – Shell Scripts Using Simple Commands

File Name: [Link]

Instructions:
1. Create a script that:
- Asks the user to enter two numbers
- Performs addition, subtraction, multiplication, and division
- Displays the results clearly
2. Use read, expr, or $(( )) for arithmetic operations.

Code:-

echo –n “Enter first number:”

read num1

echo –n “Enter first number:”

read num1

add=$((num1 + num2))

sub=$((num1 - num2))

mul=$((num1 * num2))

div=$((num1 / num2))

echo “ Addition: $add”

echo “ Subtraction: $sub”

echo “ Multiplication: $mul”

echo “ Division: $div”

Conclusion:
Assignment 3 – Shell Scripts Using Simple Commands

In this practical, I successfully created and executed three shell scripts


demonstrating the use of basic Linux commands and scripting techniques.

 Part A :- Displayed system and user information using commands like


whoami, date, pwd, and ls, helping to understand how to retrieve basic
system details.
 Part B:- Focused on file and directory operations using commands such as
mkdir, cd, touch, and ls, enhancing understanding of file management in
Linux.
 Part C:- Implemented simple arithmetic operations using shell scripting and
arithmetic expressions, showcasing how user input and basic calculations can
be handled efficiently.

You might also like