0% found this document useful (0 votes)
6 views

LabReport-2_A2_0242220005101251

The lab report focuses on advanced user input and conditional scripting techniques in Bash. It includes examples of capturing user input, handling multiple inputs, and implementing conditional statements for various scenarios such as age classification and user registration. Key points highlight the use of specific flags and syntax for effective scripting.

Uploaded by

monir22205101251
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)
6 views

LabReport-2_A2_0242220005101251

The lab report focuses on advanced user input and conditional scripting techniques in Bash. It includes examples of capturing user input, handling multiple inputs, and implementing conditional statements for various scenarios such as age classification and user registration. Key points highlight the use of specific flags and syntax for effective scripting.

Uploaded by

monir22205101251
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

Lab Report

Course Title : Operating Systems Lab


Course Code : CSE 324

Topic : Advanced User Input and Conditional Scripting in


Bash

Submitted To
Name : Nushrat Jahan Oyshi
Designation : Lecturer Computer Science & Engineering
Daffodil International University

Submitted By
Name : Kazi Tawhid Ibn Monir
Id : 0242220005101251
Section : 63_A - (A2)
Daffodil International University

DIU 2/5/2025
1. Objective
Demonstrate advanced user input and conditional statement techniques in Bash shell scripting

2. User Input Techniques


Example: Simple Name Capture-

#!/bin/bash read -p "Enter Your Name: " username

echo "Hello, $username!"

Key Points:

1. -p flag allows prompt message


2. $REPLY automatically stores input
3. Direct variable assignment possible

Example: Collecting Multiple Names-

#!/bin/bash read -p "Enter 3 Names (space-separated): " -a names

echo "First Name: ${names[0]}"

echo "Second Name: ${names[1]}"

echo "Third Name: ${names[2]}"

Key Points:

• -a flag creates an array


• Array indexing starts at 0
• Space-separated inputs

Example: Username and Password-

#!/bin/bash

read -p "Enter Username: " username

read -sp "Enter Password: " password

DIU 2/5/2025
echo -e "\nUsername: $username"

echo "Password securely captured"

Key Points:

• -s flag hides input


• Prevents password visibility
• Secure input method

3. Conditional Statements
Example: Number Comparison-

#!/bin/bash

count=15

if (( count > 10 ))

then

echo "Count is greater than 10"

fi

if [ $count -gt 10 ]

then

echo "Count is greater than 10"

fi

Key Points:

• (( )) for arithmetic operations


• [ ] for traditional test conditions
• -gt means "greater than"

DIU 2/5/2025
Example: Age-based Classification-

#!/bin/bash

read -p "Enter your age: " age

if [ $age -lt 18 ]

then

echo "Minor"

elif [ $age -ge 18 ] && [ $age -lt 60 ]

then

echo "Adult"

else

echo "Senior Citizen"

fi

Key Points:

• Multiple condition checking


• && for logical AND
• Comprehensive age categorization

Example: User Registration-

#!/bin/bash

read -p "Enter Username: " username

read -sp "Enter Password: " password

echo -e "\n"

if [ ${#password} -ge 8 ]

then

echo "Registration Successful!"

DIU 2/5/2025
else

echo "Password too short. Registration Failed."

Fi

Key Points:

• Combines secure input


• Password length validation
• ${#password} gives string length

DIU 2/5/2025

You might also like