shell - */ 中 d 的 shell 脚本;do 在本地运行,但在 circleci 中不起作用
问题描述
我构建了一个脚本,当我尝试在本地运行它时它工作正常,但是当我在 circleci 上运行它时出现错误。
这是脚本
#!/usr/bin/env bash
for d in */ ; do
cd $d
for f in * ; do
if [[ $f == *.sh ]]; then
if [[ $d == "test/" ]]; then
echo "$d"
else
bash *.sh
fi
else
if [[ $f == *.yaml ]]; then
echo "$file"
fi
fi
done
cd ..
done
这是我在 ci 上遇到的错误
generate-docs.sh: 4: cd: can't cd to */
generate-docs.sh: 6: [[: not found
generate-docs.sh: 15: [[: not found
解决方案
关于线路
bash *.sh
您似乎想一次运行所有脚本。假设 shell 文件是“a.sh”、“b.sh”、“c.sh”等,那么 shell 将其扩展为bash a.sh b.sh c.sh ...
意味着第一个(按字母顺序)运行,所有其他文件作为参数给出。您需要循环,一次执行一个。但是你已经在一个循环中,所以你需要的是
bash "$f"
推荐阅读
- pdf - 使用 Apache Poi 库在 android 中将 docx 或 doc 转换为 PDF
- python - 如何使用python中的for循环从数据框中返回每列的最大值
- javascript - 使用 npm config 在 NodeJS 中配置文件
- hive - 在 Hive 中,有没有办法在 Y 列之前添加 X 列
- android - 为什么我录制的视频在使用改造上传到服务器后变成 0 字节?
- react-native - react-native 中的 ckeditor 实现
- java - 如何在数组列表中显示符号之前将数据存储到字符串?
- python - 在 Windows 上的 PyCharm 中安装 PyAudio
- sql - 带有年份条件的 SQL 语句
- php - Paypal-PHP-SDK V2 是否支持 Webhooks?