Untitled
unknown
plain_text
2 years ago
511 B
4
Indexable
#!/bin/bash
# Define a function to check if a string is a number
is_number() {
# Use a regular expression to match only digits
if [[ $1 =~ ^[0-9]+$ ]]; then
return 0 # True
else
return 1 # False
fi
}
# Ask the user for a number
read -p "Enter a number: " input
# Loop until the user enters a valid number
while ! is_number "$input"; do
echo "That's not a number. Try again."
read -p "Enter a number: " input
done
# Echo the user's input
echo "You entered: $input"
Editor is loading...