1. 程式人生 > >[Bash] 陣列 - 列印不包含a和A的國家名

[Bash] 陣列 - 列印不包含a和A的國家名

#!/bin/bash
read cnty
idx=0
while [ -n "$cnty" ]
do
    arr[idx]="$cnty"
    read cnty
    let idx+=1
done

for i in ${!arr[@]}
do
    if [[ ${arr[i]} != *a* ]] && [[ ${arr[i]} != *A*  ]];
    then
        echo "${arr[i]}"
    fi
done
#https://www.hackerrank.com/challenges/bash-tutorials-filter-an-array-with-patterns/problem
#https://blog.csdn.net/rznice/article/details/71086839