Shell 分隔字符串为数组
2021-07-13 10:04
标签:[1] 数组 shel done bash str class lov nbsp echo "arr[0] is: ${arr[0]}" 分隔后的每一项 分割后的数组长度 存储整个索引值 Shell 分隔字符串为数组 标签:[1] 数组 shel done bash str class lov nbsp 原文地址:https://www.cnblogs.com/faithfu/p/9542486.html#!/bin/bash
tmp="test,girl,boy,love"
OLD_IFS="$IFS"
IFS=","
arr=($a)
IFS="$OLD_IFS"
echo "arr len: ${#arr[@]}"for s in ${arr[@]}
do
echo "$s"
done
存储老的分隔符
OLD_IFS="$IFS"
设置分隔符
IFS=","
按着分隔符IFS自动分隔
arr=($a)分隔后的全部数组
${arr[@]}
${arr[0]} ${arr[1]} ...
${#arr[@]}
${!arr[@]}