2017年2月21日 星期二

read 從變數中讀取資料

A=a;
read r1 <<<$A;

B=b
r2=$(echo $B |while IFS= read -r r2;do :;echo $r2;done;);
echo = $r1 = $r2 =

A=$(echo -e "a1\nb1\n");
read r1 r2 <<<$A;
echo = $r1 = $r2 =


x1="1.2.3"
read a1 a2 a3<<<${x1//./ }
echo =$a1 =$a2 =$a3

x="1 2 3 4 5 6";
i=1;
while read -d " "; do :; eval "xx${i}=$REPLY";i=$(($i+1)); done <<<$x;
echo $xx1 $xx2 $xx3 $xx4;

沒有留言: