首页 > 解决方案 > */ 中 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

标签: shellshcircleci

解决方案


关于线路

bash *.sh

您似乎想一次运行所有脚本。假设 shell 文件是“a.sh”、“b.sh”、“c.sh”等,那么 shell 将其扩展为bash a.sh b.sh c.sh ...意味着第一个(按字母顺序)运行,所有其他文件作为参数给出。您需要循环,一次执行一个。但是你已经在一个循环中,所以你需要的是

bash "$f"

推荐阅读