我有以下代码段,可以在ubuntu的终端应用程序中正常工作,但是相同的代码在MINGW(git bash在Windows中使用的shell)中表现异常。
while true;
do
while IFS=, read -r x owner login_name
do
echo "$x $owner $login_name" # putting this makes it work on MINGW
getVisitors "$x" "$owner" "$login_name"
done<"${machines}"
done
function join_by { local IFS="$1"; shift; echo "$*"; }
function getVisitors
{
machine="$1"
team="$2"
user="$3"
echo "Running ${cmd} on ${machine}"
result=$(ssh -q -i "${key_file}" -o ConnectTimeout=1 -o BatchMode=yes -o StrictHostKeyChecking=no -t ${user}@${machine} ${cmd})
isMachineUp=$?
ips=()
for visitor in ${result}
do
shopt -s nocasematch
if [[ ! "$visitor" =~ $myHostName.* ]];then
ips+=("${visitor}")
fi
shopt -u nocasematch
done
if [[ $isMachineUp -ne 0 ]];then
ips=("-");
else
if [[ $ips == "" ]];then
ips="-";
fi
fi
echo "Users found on $machine === > $ips"
addMachine $(join_by , "${ips}") "${machine}" "${team}"
}
上面的代码应该永远循环,并逐行解析“ $ {machines}”文件,该文件是一个csv文件,类似于下面给出的文件。
foo,-,admin
bar,-,admin
dor,-,admin
但是,该代码段仅解析MINGW
shell环境中的第一行。