In the below code, the array length is 1.
Could anyone explain why, as grep output will displayed in each new line but when it is stored in the array, the array length will be 1.
How to display each line reading the array?
#!/bin/bash
NUM=()
SHORT_TEXT=()
LONG_TEXT=()
#cat /tmp/dummy2 |
while read NUM
do
LONG_TEXT+=$(grep $NUM -A4 RtpLogShm.Msg | grep -vi abate | grep ^LG)
done < /tmp/dummy2
#cat /tmp/dummy1 |
while read LINE
do
NUM+=$(echo $LINE | awk -F':' '{print $1}')
SHORT_TEXT+=$(echo $LINE | awk -F':' '{print $2}')
done < /tmp/dummy1
printf "[%s]\n" "${LONG_TEXT[@]}"
done
done
在bash中,追加到数组的语法是(例如,我们要将存储在${new_element}
的元素追加到现有数组${array[@]}
):
array=("${array[@]}" "${new_element}")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.