linux - shell script array range data from a variable -
i trying expand server names in host file, following format
#hostfile server0[1-2]1 server1[2-3]4 #end i manually changed entry in hostfile i.e server0[1-2]1 (server0{1..2}1) , tried following in bash shell , able expand variable:
my_array=(server0{1..2}1) printf '%s\n' "${my_array[@]}" output: server011 server021 but when try same through script not printing output in above mat here prints following:
server0{1..2}1 server1{2..3}4 is problem in variable array conversion?
script: #!/bin/bash grep -ev '#|^$' hostfile | while read line; my_array=() if [ echo $line|grep -c 'host1' -eq 1 ]; echo $line >> new_hostfile elif [ echo $line|grep -c '^s' -eq 1 ] m=echo $line|sed -e 's/:/../g' -e 's/\[/{/g' -e 's/\]/}/g' my_array="($m)" printf '%s\n' "${my_array[@]}" >> new_hostfile fi; done
the output desired script is
server011 server021 server124 server134
Comments
Post a Comment