turn shell string array

 

#! / bin / the bash
 String = " Hello, the shell, Split, Test "  
# will, replaced with spaces 
Array = ($ { String // , /})   
 
for  var  in $ {Array [@]}
 do 
   echo $ var 
DONE

Export

bogon:conf macname$ ./test.sh 
hello
shell
split
test

 

It can also be written as

#!/bin/bash
string="hello,shell,split,test"  
array=(`echo $string | tr ',' ' '` )  
 
for var in ${array[@]}
do
   echo $var
done 
 

or

#! / bin / bash
 String = " the Hello, shell, Split, the Test "   
 
# of IFS variable replacement processing 
OLD_IFS = " $ IFS " 
IFS = " , " 
Array = ($ String ) 
IFS = " $ OLD_IFS " 
 
for  var  in Array {$ [@]}
 do 
   echo $ var 
DONE

 

 

 

reference:

https://blog.csdn.net/u010003835/article/details/80750003

 

Guess you like

Origin www.cnblogs.com/sea-stream/p/11403174.html