1. tr 커맨드를 활용하는 방법
#!/bin/bash STR="123,456,567 5,343" STR_ARRAY=(`echo $STR | tr "," "\n"`) for x in "${STR_ARRAY[@]}" do echo "> [$x]" done > [123] > [456] > [567] > [5] > [343]
2. IFS(Internal Field Separator) 를 활용하는 방법
#!/bin/bash STR="123,456,567 5,343" OLD_IFS="$IFS" IFS="," STR_ARRAY=( $STR ) IFS="$OLD_IFS" for x in "${STR_ARRAY[@]}" do echo "> [$x]" done > [123] > [456] > [567 5] > [343]
3. read 커맨드를 활용하는 방법
#!/bin/bash STR="123,456,567 5,343" IFS="," read -ra STR_ARRAY <<< "$STR" for x in "${STR_ARRAY[@]}" do echo "> [$x]" done > [123] > [456] > [567 5] > [343]
4. set 커맨드를 활용하는 방법
#!/bin/bash STR="123,456,567 5,343" set -- "$STR" IFS=","; declare -a STR_ARRAY=($*) for x in "${STR_ARRAY[@]}" do echo "> [$x]" done > [123] > [456] > [567 5] > [343]