对文件夹中的所有文件运行终端命令

发布于 2025-01-14 12:04:05 字数 669 浏览 3 评论 0原文

我有一个 models 文件夹,其中包含一堆 sql 文件 models/mart/table1.sqlmodels/mart/table2.sqlmodels/mart/table3 .sql

我在终端上手动运行此命令:

dbt run-operation generate_model_yaml --args '{"model_name": "table1"}'

但是,我不想为每个表单独运行它,而是想将其包含在 Bitbucket 管道中。如何修改该命令,使其在循环中运行?它应该从指定文件夹(models/mart)中提取所有文件的表名(文件名),然后通过每次用文件名替换 model_name 来相应地运行命令?

pipelines:
  custom: 
    dbt-run-default:
          - step:
              name: 'Compile'
              image: fishtownanalytics/dbt:1.0.0
              script:
                - cd dbt_4flow
                - dbt deps --profiles-dir ./profiles

I have a models folder which contains a bunch of sql files models/mart/table1.sql, models/mart/table2.sql, models/mart/table3.sql

I run this command manually on the terminal:

dbt run-operation generate_model_yaml --args '{"model_name": "table1"}'

However, instead of running it individually for each table, I want to include it in the Bitbucket pipeline. How can I modify the command such that it runs in a a loop? It should extract the tablename (filename) for all files from a specified folder (models/mart) and then run the command accordingly by replacing the model_name by the filename each time?

pipelines:
  custom: 
    dbt-run-default:
          - step:
              name: 'Compile'
              image: fishtownanalytics/dbt:1.0.0
              script:
                - cd dbt_4flow
                - dbt deps --profiles-dir ./profiles

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薯片软お妹 2025-01-21 12:04:05

试试这个 Shellcheck - 干净的代码:

#! /bin/bash -p

sql_dir=$1

shopt -s nullglob
for sql_path in "$sql_dir"/*.sql; do
    sql_name=${sql_path##*/}
    table_name=${sql_name%.sql}
    dbt run-operation generate_model_yaml --args '{"model_name": "'"${table_name}"'"}'
done

Try this Shellcheck-clean code:

#! /bin/bash -p

sql_dir=$1

shopt -s nullglob
for sql_path in "$sql_dir"/*.sql; do
    sql_name=${sql_path##*/}
    table_name=${sql_name%.sql}
    dbt run-operation generate_model_yaml --args '{"model_name": "'"${table_name}"'"}'
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文