[問題] 把回傳值按每一行存入array

作者: jacobcan118 (jacobcan118)   2014-10-31 13:20:44
Hi
請問一下我想把tmp的值照一行行存入一個array, 希望rtn=("something is wrong 1","something is wrong 2","something is wrong 3").
除了改IFS或把空格以其他字串取代再換回來 有更好的寫法嗎? 謝謝
code:
tmp=`cat txt`
rtn=(`echo "tmp"`)
for ((i=0; i<${#rtn[@]}; i++))
do
echo ${rtn[i]}
done
希望結果
+ rtn='something is wrong 1
something is wrong 2
something is wrong 3'
+ (( i=0 ))
+ (( i<3 ))
+ echo something is wrong 1
something is wrong 1
+ (( i++ ))
+ (( i<3 ))
+ echo something is wrong 2
something is wrong 2
+ (( i++ ))
+ (( i<3 ))
+ echo something is wrong 3
something is wrong 3
+ (( i++ ))
+ (( i<3 ))

Links booklink

Contact Us: admin [ a t ] ucptt.com