使用echo,read将字符串分割为数组

・1 分钟阅读

将字符串拆分为数组的函数

read -a ARR <<<'world domination now!'; echo ${ARR[2]};
示例输出
read -a ARR <<<'world domination now!'; echo ${ARR[2]};
now!
IFS=":" read -a ARR <<<"$PATH"; echo ${ARR[2]};
/usr/local/bin
Hujiuxiang profile image