首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用循环执行多个yarn脚本

使用循环执行多个yarn脚本
EN

Stack Overflow用户
提问于 2021-07-20 18:58:27
回答 1查看 19关注 0票数 0

我正在尝试引导一个伪CI来手动运行,并且我正在重构我的基本bash脚本:

代码语言:javascript
复制
echo '=========> yarn format <========='
yarn format

echo '=========> yarn test:cov <========='
yarn test:cov

echo '=========> yarn test:inte <========='
yarn test:inte

echo echo '=========> yarn test:e2e <========='
yarn test:e2e

echo '=========> yarn build <========='
yarn build

代码语言:javascript
复制
#!/bin/zsh
scripts=(
  'yarn format'
  'yarn test:cov'
  'yarn test:inte'
  'yarn test:e2e'
  'yarn build'
)

for script in "${scripts[@]}"
do
  printf '\n=========> %s <=========\n' "$script"
  $script
done

但是,如果第一个脚本运行得很好,那么循环版本会将此结果作为输出:

代码语言:javascript
复制
➜  back git:(refactor/remove-decoupling) ✗ yarn ci
$ ./tmtc-ci.sh

=========> yarn format <=========
./tmtc-ci.sh:13: command not found: yarn format

=========> yarn test:cov <=========
./tmtc-ci.sh:13: command not found: yarn test:cov

=========> yarn test:inte <=========
./tmtc-ci.sh:13: command not found: yarn test:inte

=========> yarn test:e2e <=========
./tmtc-ci.sh:13: command not found: yarn test:e2e

=========> yarn build <=========
./tmtc-ci.sh:13: command not found: yarn build
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜  back git:(refactor/remove-decoupling) ✗
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-20 19:45:26

我刚刚找到了我的问题的答案:

eval "$script"

因为我的脚本数组只包含我所理解的字符串。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68453714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档