1.)write a shell script that displays a digital clock and a calendar side by side in the terminal. It updates every second. #!/bin/bash # Function to display digital clock and calendar side by side show_clock_calendar() { while true; do clear # Clears the screen for real-time updates # Get current time and date TIME=$(date +"%H:%M:%S") DATE=$(date +"%A, %d %B %Y") # Get current month's calendar CALENDAR=$(cal) # Display Digital Clock & Calendar side by side echo "==============================================" echo " DIGITAL CLOCK CALENDAR " echo "==============================================" echo "" printf " Time: %s %s\n" "$TIME" "$(date +"%B %Y")" printf " Date: %s\n\n" "$DATE" # Print calendar in a formatted way paste <(echo "$CALENDAR") <(printf "\n\n\n\n\n") echo "" echo "==============================================" sleep 1 # Refresh every second done } # Call the function show_clock_calendar =============================================================================================================== 2).Write a shell script that uses a switch-case (case statement) to let the user: 1️⃣ Check if a file exists 2️⃣ Check if a directory exists 3️⃣ Check if a file is empty #!/bin/bash # Function to check if a file exists check_file() { echo "Enter the file name:" read filename if [ -f "$filename" ]; then echo "File '$filename' exists." else echo "File '$filename' does not exist." fi } # Function to check if a directory exists check_directory() { echo "Enter the directory name:" read dirname if [ -d "$dirname" ]; then echo "Directory '$dirname' exists." else echo "Directory '$dirname' does not exist." fi } # Function to check if a file is empty check_empty_file() { echo "Enter the file name:" read filename if [ -f "$filename" ]; then if [ ! -s "$filename" ]; then echo "File '$filename' is empty." else echo "File '$filename' is not empty." fi else echo "File '$filename' does not exist." fi } # Main menu using case statement echo "Choose an option:" echo "1. Check if a file exists" echo "2. Check if a directory exists" echo "3. Check if a file is empty" echo "4. Exit" read choice case $choice in 1) check_file ;; 2) check_directory ;; 3) check_empty_file ;; 4) echo "Exiting..."; exit ;; *) echo "Invalid option. Please enter a valid choice." ;; esac ================================================================================================================= 3).write a shell script that takes a list of numbers as input from the user and sorts them in ascending order using the Bubble Sort method. #!/bin/bash # Function to perform Bubble Sort bubble_sort() { local -n arr=$1 # Use a nameref to modify the original array local n=${#arr[@]} # Get the number of elements in array for ((i = 0; i < n-1; i++)); do for ((j = 0; j < n-i-1; j++)); do if (( arr[j] > arr[j+1] )); then # Swap arr[j] and arr[j+1] temp=${arr[j]} arr[j]=${arr[j+1]} arr[j+1]=$temp fi done done } # Read numbers from user echo "Enter numbers separated by space: " read -a numbers # Read input as an array # Call bubble sort function bubble_sort numbers # Display sorted numbers echo "Sorted numbers in ascending order: ${numbers[@]}" =============================================================================================================================== 4).write a shell script that lets the user enter a number and checks whether it's an Armstrong number using a function. #!/bin/bash # Function to check if a number is Armstrong is_armstrong() { local num=$1 local sum=0 local digit local temp=$num # Get number of digits local n=${#num} # Calculate sum of digits raised to the power of n while [ $temp -gt 0 ]; do digit=$((temp % 10)) sum=$((sum + digit ** n)) temp=$((temp / 10)) done # Check if the number is Armstrong if [ $sum -eq $num ]; then echo "$num is an Armstrong number." else echo "$num is NOT an Armstrong number." fi } # Main Script echo "Enter a number:" read number # Validate input if ! [[ "$number" =~ ^[0-9]+$ ]]; then echo "Invalid input. Please enter a positive integer." exit 1 fi # Call the function is_armstrong "$number"