actions_example/primes.sh
kiper220 a5430fb5fb
All checks were successful
Caching Primes / build (push) Successful in 9s
/ ls (push) Successful in 4s
feat: add demo workflows
2025-02-07 22:48:39 +04:00

34 lines
761 B
Bash
Executable file

#!/bin/bash
# Handling arguments
while getopts "d:" opt; do
case $opt in
d)
file_name=$OPTARG
;;
*)
echo "Usage: $0 -d <file_name>"
exit 1
;;
esac
done
if [ -z "$file_name" ] || [ ! -f "$file_name" ]; then
echo "File not found or not specified. Usage: $0 -d <file_name>"
exit 1
fi
# Reading a file and converting its contents into an array
mapfile -t numbers < <(tr ' ' '\n' < "$file_name")
# Number of elements
count=${#numbers[@]}
echo "Number of elements: $count"
# First 10 elements
first_ten=("${numbers[@]:0:10}")
echo "First 10 elements: ${first_ten[*]/,/, }"
# Last 10 elements
last_ten=("${numbers[@]: -10}")
echo "Last 10 elements: ${last_ten[*]/,/, }"