【发布时间】:2017-11-28 13:29:30
【问题描述】:
我不确定这是否是发布此内容的合适位置,不过如此:我正在开发一个脚本来否定匹配 git 分支,但是当这部分运行时,它试图获取 HTTP 标头... .谁能解释这是怎么回事?
test.sh
#!/bin/bash
array_not_contains()
{
local array="$1[@]"
local seeking=$2
local in=0
for element in "${!array}"; do
echo $element #Commenting out this echo will stop it from fetching headers
if [[ $element =~ $seeking ]]; then
in=1
break
fi
done
return $in
}
exclude=() #array that will exclude the following matches from deletion
exclude+=(HEAD)
exclude+=(master)
exclude+=(develop)
exclude+=(example.*)
if $(array_not_contains exclude $1); then
echo "win"
else
echo "fail"
fi
像这样运行它: ./test.sh 鲍勃 将返回标题
【问题讨论】:
-
添加
set -x看看发生了什么。