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.