一、比如以空格为分割将字符串转为数组
方法一: 借助于{str// /}来处理
[root@host ~]# str="1 2 3 4 5"
[root@host ~]# result=(${str// /})
[root@host ~]# echo ${result[@]}
12345
方法二: 借助于IFS来处理分隔符
[root@host ~]# str="1 2 3 4 5"
[root@host ~]# IFS=" "
[root@host ~]# result=(str)
[root@host ~]# echo ${str[@]}
${str[@]} #获取数组的所有元素
二、在shell脚本中执行linux命令
比如要执行“ls -l /home”,并赋值给变量result
result=`ls -l /home` #两边的``不是单引号,而是反引号,键盘的“~”键。
可以在反引号中执行相关的命令。