19.Write a shell script to change case of string.
#!/bin/bash
# Read input from the user
read -p "Enter a string: " input
# Prompt for case conversion choice
echo "Choose an option:"
echo "1. Convert to UPPERCASE"
echo "2. Convert to lowercase"
read -p "Enter choice (1 or 2): " choice
# Change case based on user choice
if [ "$choice" -eq 1 ]; then
output=$(echo "$input" | tr '[:lower:]' '[:upper:]')
echo "Converted to UPPERCASE: $output"
elif [ "$choice" -eq 2 ]; then
output=$(echo "$input" | tr '[:upper:]' '[:lower:]')
echo "Converted to lowercase: $output"
else
echo "Invalid choice. Please enter 1 or 2."
exit 1
fi
Comments
Post a Comment