- bookbean 's Newsletter
- Posts
- Hello, No Information
Hello, No Information
I want only to be more good at Continuity
#!/bin/bash
#
# mega_example.sh - A large Bash example with many features
#
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Global variables
LOGFILE="./mega_example.log"
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
# Array of motivational quotes
QUOTES=(
"Stay hungry, stay foolish."
"Code is like humor. When you have to explain it, it’s bad."
"Before software can be reusable it first has to be usable."
"Don’t document the problem, fix it."
"Simplicity is the soul of efficiency."
)
# Log function
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" >> "$LOGFILE"
}
# Random quote
quote() {
rand=$((RANDOM % ${#QUOTES[@]}))
echo -e "${CYAN}${QUOTES[$rand]}${NC}"
log "Displayed a motivational quote."
}
# Math function (sum, subtract, multiply, divide)
math_menu() {
echo -e "${YELLOW}Math Operations${NC}"
read -p "Enter first number: " a
read -p "Enter second number: " b
echo "1) Add"
echo "2) Subtract"
echo "3) Multiply"
echo "4) Divide"
read -p "Choose: " op
case $op in
1) echo -e "${GREEN}Result: $((a+b))${NC}" ;;
2) echo -e "${GREEN}Result: $((a-b))${NC}" ;;
3) echo -e "${GREEN}Result: $((a*b))${NC}" ;;
4)
if [[ $b -eq 0 ]]; then
echo -e "${RED}Error: Division by zero${NC}"
else
echo -e "${GREEN}Result: $((a/b))${NC}"
fi
;;
*) echo -e "${RED}Invalid option${NC}" ;;
esac
log "Math operation performed."
}
# Generate random numbers and save to file
random_numbers() {
read -p "How many random numbers? " count
read -p "Save to file name: " fname
> "$fname"
for ((i=1;i<=count;i++)); do
echo $RANDOM >> "$fname"
done
echo -e "${GREEN}Saved $count random numbers to $fname${NC}"
log "Generated $count random numbers into $fname."
}
# Show system info
sys_info() {
echo -e "${YELLOW}System Info${NC}"
echo "User: $USER"
echo "Date: $DATE"
echo "Uptime: $(uptime -p)"
echo "Disk: $(df -h / | awk 'NR==2{print $4 " free"}')"
log "Displayed system info."
}
# Menu loop
while true; do
echo -e "\n${CYAN}====== Mega Bash Example ======${NC}"
echo "1) Show motivational quote"
echo "2) Math operations"
echo "3) Generate random numbers"
echo "4) Show system info"
echo "5) View log file"
echo "6) Exit"
echo "================================="
read -p "Choose an option: " choice
case $choice in
1) quote ;;
2) math_menu ;;
3) random_numbers ;;
4) sys_info ;;
5) cat "$LOGFILE" ;;
6) log "Exiting script."; break ;;
*) echo -e "${RED}Invalid choice!${NC}" ;;
esac
done
This is an AI code ….. I didn’t make it 😁
BookBean