bash help-为匹配模式的文件夹运行命令的脚本

bash help-为匹配模式的文件夹运行命令的脚本,bash,kubectl,Bash,Kubectl,我想创建一个脚本,可以为这里的每个逻辑组运行k apply-Rf./service token auth。主要是所有graphql-*和data service-*文件夹 这是不是很容易实现 $ ls README.md data-service-notifications orchestration-workflows-service argo-cd data-service-reports

我想创建一个脚本,可以为这里的每个逻辑组运行
k apply-Rf./service token auth
。主要是所有graphql-*和data service-*文件夹

这是不是很容易实现

$ ls
README.md                       data-service-notifications      orchestration-workflows-service
argo-cd                         data-service-reports            postgresql-operator
argocd                          data-service-user               prometheus
azure-identities                diagnostic-tools                pushgateway
azure-nginx-ingress             gloo-gateway                    reloader
azure-private-dns               graphql-gateway                 service-auth
azure-rbacs                     graphql-service-applications    service-b2c-gateway
azure-secrets                   graphql-service-clients         service-dast-auth
blackbox-exporter               graphql-service-findings        service-dast-ml
cadence                         graphql-service-logging         service-mesh
data-service-application        graphql-service-user            service-token-auth
data-service-clients            kube-state-metrics              strimzi-kafka
data-service-findings           kuberhealthy                    tartarus
data-service-logging            kubernetes-reflector            whs-opa

您可以在bash中迭代文件

首先,确保它只命中您想要的文件夹

for i in graphql-* data-service-*; do echo $i; done
然后执行

for i in graphql-* data-service-*; do k apply -Rf ./$i; done

是否要进入这些文件夹并运行脚本?不,抱歉,我希望使用每个文件夹的参数运行该命令。我想要一个脚本,它将执行:k apply-Rf./graphql服务应用程序k apply-Rf./graphql服务客户端等等,这正是我想要的,谢谢!