从grep到计数范围变量Bash OpenWRT的行数

时间:2013-12-11 06:44:59

标签: bash grep openwrt

我试图在for循环中使用格式为0 ..#的范围。我目前有这个,但它没有正确地抓住计数。我试图在OpenWRT上运行它。

count=echo $(( ${grep -c BSS /tmp/ScannedAPs.txt} - 1 ))

错误:${grep -c BSS /tmp/ScannedAPs.FLT}: bad substitution

range="0..$count"

echo "Count:"
echo "$count"
echo "Time for range"
echo "$range"

for index in $(eval echo "{$range}")
do
echo "${BSS[index]} ${SSID[index]} ${CHAN[index]}" >> /tmp/ScannedAPs_Parsed.txt
done

1 个答案:

答案 0 :(得分:1)

如您所示,错误发生在:

count=echo $(( ${grep -c BSS /tmp/ScannedAPs.txt} - 1 ))

Command Substitution的正确语法是$(command)。说:

count=$(( $(grep -c BSS /tmp/ScannedAPs.txt) - 1 ))

此外,您可以{/ 3}}:

for index in $(eval echo "{$range}")

说:

for index in $(seq 0 $count)

或者,你可以通过说:

循环(由ruakh作为avoid using eval
for ((index=0;index<=count;index++)); do
  # Do something here
done