The document is a Bash script that checks if input numbers are prime. It prompts the user to enter numbers, validates them, and identifies which are prime, displaying the results. If no valid prime numbers are found, it notifies the user accordingly.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views2 pages
Main Bash
The document is a Bash script that checks if input numbers are prime. It prompts the user to enter numbers, validates them, and identifies which are prime, displaying the results. If no valid prime numbers are found, it notifies the user accordingly.
if [[ $ {#input_numbers[@]} -eq 0 ]]; then echo "Error: No numbers provided" exit 1 fi
# Array to store prime numbers
declare -a primes_found
# Process each number in the input
for number in "${input_numbers[@]}"; do # Validate that the input is a positive integer if [[ ! $number =~ ^[0-9]+$ ]]; then echo "Warning: '$number' is not a valid integer, skipping" continue fi
# Check if number is prime and store if true
if [[ $(is_prime "$number") == "true" ]]; then primes_found+=("$number") fi done
# Display the results
if [[ $ {#primes_found[@]} -eq 0 ]]; then echo "No prime numbers found in the input" else echo "Prime numbers: ${primes_found[*]}" echo "Total prime numbers: ${#primes_found[@]}" fi