@把命令运行结果赋值给变量@
result=`grep-o 'href' $website_address1|wc -l`
@如何把文件中的每一行赋值给一个数组@
array=($(catfile))
array=(a bc def)
echo ${array[@]} //取全部元素 a b c def
echo${array[0]} //取第一个元素 a
echo${#array[@]} //取得数组元素的个数4
@SHELL读取一行@
while read-r line
do
iter=$(($iter+1))
# curl --limit-rate 64k $line -o ../website$iter.html
curl --limit-rate 64k -O $line
# done < $FILEOUTPUT
done < $FILEOUTPUT.test
@从一行中读取若干值放入变量中@
例1
cat /etc/passwd |
while IFS=: read user pass uid gid fullname homedir shell
do
#处理每一行记录
echo welcome $user
done
例2
if [ -s "$INDEX_WEBSITE_LIST"]
then
while IFS=$'\t' read domain_temp page_name count_iter pid
do
domain_result=${domain_temp%%/*}
curl -s --retry 1 --retry-delay 1--retry-max-time 2 --max-time 5 --limit-rate 1024k $page_name -o$FETCH_WEBSITE_DIR/$count_iter"-"$domain_result.html
done < $INDEX_WEBSITE_LIST
else
echo "$INDEX_WEBSITE_LIST is empty and now exits."
exit
fi
@读文件到一个数组,文件中的每一行作为数组的一个元素@
例1
website_array3=($(cat$ SOURCE_FILE))
iter3=0
while [ "$iter3" -lt ${#website_array3[@]} ]
do
website_address3=${website_array3[$iter3]}
is_culpable $website_address3 $ OUPTUT_FILE
iter3=$(($iter3+1))
done