1,124   Linux Shell

#!/bin/bash

##
# function start
##

function test_ifs
{
	local STR="a|b|c"
	local ARR
	local OLD_IFS="$IFS"
        # | 作为分割
	IFS="|"
	echo -e "\n"
	echo -e "Befor : ${STR} \n"
        # 分割成数组
	ARR=(${STR})
	IFS="$OLD_IFS"
	echo -e "\n"
	echo -e "After : \n"
        # 输出
	for ((i=0;i<${#ARR[@]};i++))
	do
		echo ${ARR[$i]}
	done
	

}




function run_main
{
	test_ifs
}

##
# function end
##


##
# main start
##

run_main


##
# main end
##



Leave a Reply

Your email address will not be published. Required fields are marked *