regex - split string in one liner in bash or ksh or perl -
var="valuea valueb"
i want split above string shown below , want read value in 1 liner on bash shell.
following script not working .
echo $var |awk '{print $1 $2}' |while read var; echo var1=$1 , var2=$2;done echo $var |awk '{ var1=$1 ; var2=$2}' |while read var1 var2; echo var1=$var1 , var2=$var2;done
in ksh93, work of shelf:
echo "$var" | read var1 var2 && echo $var1 --- $var2
effectively same https://stackoverflow.com/a/32855720/667820, values of $var1 , $var2 preserved.
for bash, need bash 4.x , options need (un)set.
Comments
Post a Comment