Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 digital clock
- echo "Digital Clock for Linux"
- echo "To exit please press ctrl + c "
- while :
- do
- clear
- tput setaf 1 # Set text color to green
- tput cup 10 69 # Adjusted position for a larger display
- date +"%r"
- #tput sgr0 # Reset text attributes
- sleep 1
- done
- 2
- #!/bin/bash
- # Function to display the sign-up form
- display_form() {
- echo "Welcome to the Sign-Up Form"
- echo "---------------------------"
- read -p "Enter your username: " username
- read -sp "Enter your password (at least 8 characters): " password
- echo
- while [ ${#password} -lt 8 ]; do
- echo "Password must have at least 8 characters."
- read -sp "Enter your password (at least 8 characters): " password
- echo
- done
- read -p "Enter your email address: " email
- echo
- echo "Thank you for signing up, $username!"
- echo "Your email address is: $email"
- }
- # Main function
- main() {
- display_form
- }
- # Calling the main function
- Main
- 3
- #!/bin/bash
- # Initialize variables to store inventory and prices
- declare -A inventory
- declare -A prices
- # Function to add items to inventory
- add_item() {
- item_name=$1
- item_quantity=$2
- item_price=$3
- inventory["$item_name"]=$item_quantity
- prices["$item_name"]=$item_price
- }
- # Function to display available items and prices
- display_inventory() {
- echo "Available Items in the Medical Store:"
- echo "-----------------------------------"
- for item in "${!inventory[@]}"; do
- echo "Item: $item - Quantity: ${inventory[$item]} - Price: ${prices[$item]}"
- done
- }
- # Function to sell items
- sell_item() {
- item_name=$1
- item_quantity=$2
- current_quantity=${inventory["$item_name"]}
- if [ "$current_quantity" -lt "$item_quantity" ]; then
- echo "Sorry, only $current_quantity $item_name(s) available."
- else
- echo "Sold $item_quantity $item_name(s) for $((item_quantity * prices["$item_name"]))"
- inventory["$item_name"]=$((current_quantity - item_quantity))
- fi
- }
- # Main function
- main() {
- add_item "Paracetamol" 50 5
- add_item "Bandages" 100 3
- add_item "Antiseptic" 30 7
- display_inventory
- echo "Welcome to the Mini Medical Store"
- echo "--------------------------------"
- read -p "Enter the item you want to purchase: " item_name
- read -p "Enter the quantity: " quantity
- sell_item "$item_name" "$quantity"
- display_inventory
- }
- # Calling the main function
- main
- 4
- #!/bin/bash
- # Initialize associative arrays to store books and their availability
- declare -A books
- declare -A availability
- # Function to add books to the library
- add_book() {
- title=$1
- author=$2
- availability["$title"]="available"
- books["$title"]=$author
- }
- # Function to display available books
- display_books() {
- echo "Available Books in the Library:"
- echo "--------------------------------"
- for title in "${!books[@]}"; do
- echo "Title: $title - Author: ${books[$title]} - Availability: ${availability[$title]}"
- done
- }
- # Function to borrow a book
- borrow_book() {
- title=$1
- if [ "${availability[$title]}" = "available" ]; then
- availability["$title"]="borrowed"
- echo "You have borrowed the book: $title"
- else
- echo "Sorry, the book $title is currently not available."
- fi
- }
- # Function to return a book
- return_book() {
- title=$1
- if [ "${availability[$title]}" = "borrowed" ]; then
- availability["$title"]="available"
- echo "You have returned the book: $title"
- else
- echo "This book is not borrowed or doesn't exist in the library."
- fi
- }
- # Main function
- main() {
- add_book "1984" "George Orwell"
- add_book "To Kill a Mockingbird" "Harper Lee"
- add_book "The Great Gatsby" "F. Scott Fitzgerald"
- display_books
- echo "Welcome to the Mini Library Management System"
- echo "---------------------------------------------"
- echo "1. Borrow a Book"
- echo "2. Return a Book"
- echo "3. Exit"
- read -p "Enter your choice: " choice
- case $choice in
- 1)
- read -p "Enter the title of the book you want to borrow: " title
- borrow_book "$title"
- ;;
- 2)
- read -p "Enter the title of the book you want to return: " title
- return_book "$title"
- ;;
- 3)
- echo "Exiting..."
- ;;
- *)
- echo "Invalid choice. Please enter a valid option."
- ;;
- esac
- display_books
- }
- # Calling the main function
- main
- 5
- #!/bin/bash
- # Initialize associative arrays to store menu items and their prices
- declare -A menu
- declare -A order
- # Function to add menu items
- add_item() {
- item_name=$1
- item_price=$2
- menu["$item_name"]=$item_price
- }
- # Function to display the menu
- display_menu() {
- echo "Menu:"
- echo "-----"
- for item in "${!menu[@]}"; do
- echo "$item - ₹${menu[$item]}"
- done
- }
- # Function to take customer orders
- take_order() {
- while true; do
- read -p "Enter the item you want to order (or type 'done' to finish): " item
- if [ "$item" == "done" ]; then
- break
- elif [ -z "${menu[$item]}" ]; then
- echo "Sorry, $item is not on the menu."
- else
- read -p "Enter the quantity: " quantity
- order["$item"]=$((order["$item"] + quantity))
- fi
- done
- }
- # Function to calculate and display the total bill
- calculate_bill() {
- total=0
- echo "Order Summary:"
- echo "--------------"
- for item in "${!order[@]}"; do
- price=$((${menu[$item]} * ${order[$item]}))
- echo "$item x ${order[$item]} - ₹$price"
- total=$((total + price))
- done
- echo "Total: ₹$total"
- }
- # Main function
- main() {
- add_item "Burger" 100
- add_item "Pizza" 150
- add_item "Salad" 80
- display_menu
- echo "Welcome to the Mini Restaurant Management System"
- echo "-----------------------------------------------"
- take_order
- calculate_bill
- }
- # Calling the main function
- Main
- 6
- #!/bin/bash
- # Function to perform addition
- add() {
- echo "$1 + $2" | bc
- }
- # Function to perform subtraction
- subtract() {
- echo "$1 - $2" | bc
- }
- # Function to perform multiplication
- multiply() {
- echo "$1 * $2" | bc
- }
- # Function to perform division
- divide() {
- echo "scale=2; $1 / $2" | bc
- }
- # Main function
- main() {
- echo "Simple Calculator"
- echo "-----------------"
- echo "1. Addition"
- echo "2. Subtraction"
- echo "3. Multiplication"
- echo "4. Division"
- read -p "Enter your choice: " choice
- case $choice in
- 1)
- read -p "Enter first number: " num1
- read -p "Enter second number: " num2
- echo "Result: $(add $num1 $num2)"
- ;;
- 2)
- read -p "Enter first number: " num1
- read -p "Enter second number: " num2
- echo "Result: $(subtract $num1 $num2)"
- ;;
- 3)
- read -p "Enter first number: " num1
- read -p "Enter second number: " num2
- echo "Result: $(multiply $num1 $num2)"
- ;;
- 4)
- read -p "Enter first number: " num1
- read -p "Enter second number: " num2
- if [ "$num2" -eq 0 ]; then
- echo "Error: Division by zero"
- else
- echo "Result: $(divide $num1 $num2)"
- fi
- ;;
- *)
- echo "Invalid choice"
- ;;
- esac
- }
- # Calling the main function
- main
- 7
- #!/bin/bash
- # Function to generate a random password
- generate_password() {
- local length=$1
- tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$length" | head -n 1
- }
- # Main function
- main() {
- echo "Password Generator"
- echo "------------------"
- read -p "Enter the length of the password: " password_length
- generated_password=$(generate_password "$password_length")
- echo "Generated Password: $generated_password"
- }
- # Calling the main function
- main
- 8
- #!/bin/bash
- # Define the filename for the database
- DB_FILE="student_database.txt"
- # Function to create a new database file
- create_database() {
- touch "$DB_FILE"
- echo "Database created successfully."
- }
- # Function to view the contents of the database
- view_database() {
- echo "Student Database:"
- echo "-----------------"
- cat "$DB_FILE"
- }
- # Function to insert a new student record
- insert_record() {
- read -p "Enter student ID: " id
- read -p "Enter student name: " name
- read -p "Enter student age: " age
- echo "$id | $name | $age" >> "$DB_FILE"
- echo "Record inserted successfully."
- }
- # Function to update a student record
- update_record() {
- read -p "Enter student ID to update: " id
- read -p "Enter new name: " new_name
- read -p "Enter new age: " new_age
- sed -i "s/^$id .*/$id | $new_name | $new_age/" "$DB_FILE"
- echo "Record updated successfully."
- }
- # Function to delete a student record
- delete_record() {
- read -p "Enter student ID to delete: " id
- sed -i "/^$id/d" "$DB_FILE"
- echo "Record deleted successfully."
- }
- # Function to show a particular student record
- show_record() {
- read -p "Enter student ID to view: " id
- grep "^$id" "$DB_FILE"
- }
- # Main function
- main() {
- while true; do
- echo "Student Database Operations:"
- echo "1. Create Database"
- echo "2. View Database"
- echo "3. Insert Record"
- echo "4. Update Record"
- echo "5. Delete Record"
- echo "6. Show Record for Particular Student"
- echo "7. Exit"
- read -p "Enter your choice: " choice
- case $choice in
- 1) create_database ;;
- 2) view_database ;;
- 3) insert_record ;;
- 4) update_record ;;
- 5) delete_record ;;
- 6) show_record ;;
- 7) echo "Exiting..." && exit ;;
- *) echo "Invalid choice. Please enter a valid option." ;;
- esac
- done
- }
- # Calling the main function
- main
- 9
- #!/bin/bash
- # Define the directory where the files are located
- DIRECTORY="/home/me/gourav_upadhyay/shell"
- # Function to remove files older than 4 days based on their filenames
- remove_old_files() {
- find "$DIRECTORY" -type f -name "*.*" -mtime +4 -exec rm {} \;
- echo "Old files older than 4 days have been removed from $DIRECTORY"
- }
- # Main function
- main() {
- echo "Removing files older than 4 days in $DIRECTORY"
- remove_old_files
- }
- # Calling the main function
- main
- 10
- #!/bin/bash
- # Function to count words, lines, and characters in a text file
- count_stats() {
- file="$1"
- words=$(wc -w < "$file")
- lines=$(wc -l < "$file")
- characters=$(wc -m < "$file")
- echo "File: $file"
- echo "Words: $words"
- echo "Lines: $lines"
- echo "Characters: $characters"
- echo "---------------------"
- }
- # Main function
- main() {
- echo "Counting statistics for the provided text files"
- echo "----------------------------------------------"
- file1="/home/me/gourav_upadhyay/shell/file1.sh"
- file2="/home/me/gourav_upadhyay/shell/file2.sh"
- count_stats "$file1"
- count_stats "$file2"
- }
- # Calling the main function
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement