#!/bin/bash # Function to read and validate a non-empty string read_string_input() { local prompt_message="$1" local result_var_name="$2" local input while true; do read -p "$prompt_message: " input if [[ -n "$input" ]]; then eval "$result_var_name=\"$input\"" break else echo "Input cannot be empty. Please try again." fi done } # Function to read and validate a positive integer read_integer_input() { local prompt_message="$1" local result_var_name="$2" local input while true; do read -p "$prompt_message: " input # Check if input is an integer and positive if [[ "$input" =~ ^[0-9]+$ ]] && (( input > 0 )); then eval "$result_var_name=$input" break else echo "Invalid input. Please enter a positive integer." fi done } echo "Welcome to the interactive script!" # Get user's name read_string_input "Please enter your name" USER_NAME # Get user's age read_integer_input "Please enter your age" USER_AGE echo "" echo "Summary:" echo "Name: $USER_NAME" echo "Age: $USER_AGE" if (( USER_AGE < 18 )); then echo "You are a minor." elif (( USER_AGE >= 18 && USER_AGE < 65 )); then echo "You are an adult." else echo "You are a senior." fi echo "Thank you for your input!"