无法获取bash函数的返回值

时间:2016-08-28 12:56:44

标签: linux bash

我正在尝试运行一个脚本,我希望bash在每个实例中运行特定数量的curl语句。 不幸的是我不知道如何获取我用来计算从运行卷发的函数返回的卷发数量的局部变量。

这是我的代码:

function pusher()
{
local lines="$@"
local pushcount=0
for line in  $lines; do

    if validnumber $line; then
        #printf "$line is a valid number.\n"
        if grep -Fxq $line  results.txt; then
            echo "$line previously successfully treated." >> failures.txt
            break
        fi
        #pushing
        if is_a_personal personals ${line:0:6}; then
            /usr/bin/curl -s -k "https://192.168.2.123:567/pull?service=abc.ABCDEoboe&person=$line" > /dev/null &
            echo "$line is treated" >> results.txt
            (( pushcount++ ))
        else
            #printf "$line is not an personal number. Using others push\n"
            /usr/bin/curl -s -k "https://192.168.2.123:567/pull?service=abc.ABCDE&person=$line" > /dev/null &
            echo "$line is treated" >> results.txt
            (( pushcount++ ))
        fi

    else
        #printf "$line is NOT properly formatted or invalid.\n"
        echo "$line is NOT properly formatted or invalid." >> failures.txt
        (( pushcount++ ))
    fi


done &
echo "$pushcount"
#return $pushcount
 wait
}

xargs -L 100 -a $numberfile | while read line 
 do
    #pusher  $line
    (( count++))
    printf "$(pusher $line) messages sent using loop $count in `date +%S` seconds\n"
done

当我运行脚本时,我得到“0”或null而不是我正在寻找的pushcount的值。

0 messages sent using loop 225 in 01 seconds
0 messages sent using loop 226 in 14 seconds
0 messages sent using loop 227 in 33 seconds
0 messages sent using loop 228 in 46 seconds

请问我做错了什么,我该如何解决? 谢谢!

0 个答案:

没有答案