我创建了一个代码来解析目录中文件的主机名,用户名和特权。.但是我无法在代码末尾退出。循环给出了完整的数据输出,但没有给出shell提示背部。 数组arg []包含文件值的名称
c=0
while((c<=${#arg[*]}))
do
hname=`grep -e "^hostname" ${arg[$c]} |awk '{ print $2 }'| sort |uniq`
if [[ -n $hname ]]
then
logDebug "data found for the $hname"
while read -r line; do
for term in "echo $line"; do
if [[ "$term" =~ (username)[[:space:]](.*?) ]]; then
userid=`echo "${BASH_REMATCH[2]}" | awk '{print $1}'`
logDebug "username: $userid"
if [[ "$term" =~ (privilege)[[:space:]](.*?) ]]; then
Priv=`echo "${BASH_REMATCH[2]}" | awk '{print $1}'`
PRIV=`echo "level=$Priv"`
logDebug "Privilege: $PRIV"
echo"$CUSTOMER|S|$hname|$OS|$userid|$Uid_Conv|$Uic_mode|$State|$i_login|$group|$PRIV|" >> "$OutputFile"
fi
fi
done
done < "${arg[$c]}"
fi
let c=c+1
done
答案 0 :(得分:0)
对于您的第一个while子句...我会使用
for ((c=0;c<${#arg[*];c++)); do
.....
done
摆脱c = 0并让c = c + 1