我正在尝试引导一个伪CI来手动运行,并且我正在重构我的基本bash脚本:
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至
#!/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但是,如果第一个脚本运行得很好,那么循环版本会将此结果作为输出:
➜ 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) ✗发布于 2021-07-20 19:45:26
我刚刚找到了我的问题的答案:
eval "$script"
因为我的脚本数组只包含我所理解的字符串。
https://stackoverflow.com/questions/68453714
复制相似问题