BASH命令和SHELL脚本总结(5)赋值篇

@把命令运行结果赋值给变量@

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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值