有一个getStrings()
函数调用getPage()
函数返回一些html页面。该HTML通过egrep
和sed
组合来传递,只能获得3个字符串。然后我尝试使用while read..
构造将每个字符串分别放入单独的变量link
,profile
,gallery
。但它仅适用于while...done
循环,因为它在子进程中运行。我应该怎么做才能在getStrings()
函数之外使用这些变量?在bash中的子进程外使用变量
getStrings() {
local i=2
local C=0
getPage $(getPageLink 1 $i) |
egrep *some expression that results in 3 strings* |
while read line; do
if (((C % 3) == 0)); then
link=$line
elif (((C % 3) == 1)); then
profile=$line
else
gallery=$line
fi
C=$((C+1)) #Counter
done
}
调查'禁用了javascript -s lastpipe'。 – 2014-10-17 18:51:34