別の for ループなど、追加のコードを追加せずにこれを実行しようとしています。文字列と配列を比較する正論理を作成できます。負の論理が必要で、配列にない値のみを出力したいのですが、基本的にこれはシステム アカウントを除外するためです。
私のディレクトリには、次のようなファイルがあります。
admin.user.xml
news-lo.user.xml
system.user.xml
campus-lo.user.xml
welcome-lo.user.xml
これは、そのファイルがディレクトリにある場合に肯定的な一致を行うために使用したコードです。
#!/bin/bash
accounts=(guest admin power_user developer analyst system)
for file in user/*; do
temp=${file%.user.xml}
account=${temp#user/}
if [[ ${accounts[*]} =~ "$account" ]]
then
echo "worked $account";
fi
done
正しい方向への助けをいただければ幸いです、ありがとう。