Attached script shows a few examples eventually it is split if the receiving var is already an array, but you need to have saved and restore IFS...
questions (at end of script) why didn't statement pre-assignment work with 'echo' or 'let'?, but splitting assignment and 'echo' does work?? why doesn't same-line assignment to IFS work with with the assignment statement? (are either of these fixed in 4.3 (still haven't moved up due to broken signal delivery)... Script generates commentary .. but the questions at the end are in a comment. (got side tracked trying to figure out a faster way to fix my cygwin path when I rsh locally.. to be able to use a good & fast tty emulator) Thanks
#!/bin/bash echo "Using:" bash --version|head -1 shopt -s expand_aliases RA='declare -a' alias rs="IFS=\ $'\x09'$'\x0a'" alias sho='declare -p' hx(){ ((${#1})) && { printf "%02x " "'${1}"; hx "${1:1}"; } || echo ""; } pth=".:/Usr_bin:/system32:/System32_Wbem:/Prog64_NVIDIA GPU Computing Toolkit_CUDA_bin:/Prog_QuickTime" echo "1st try to split pth:" IFS=: echo $pth echo "IFS=$(hx "$IFS")" echo "in parens is the same:" (IFS=: echo $pth) echo "add semi after colon & it works! why didn't local assigment work?" (IFS=:; echo $pth) echo "assign pth to a, try 'let' (to make assigment, IFS still ok):" IFS=: let a=($pth) echo "IFS=$(hx "$IFS")" echo "try assign -- and but IFS is thrashed" IFS=: a=($pth) echo "'a' became an array, but didn't split on colons" sho a echo "reset IFS then try again:" rs echo "IFS=$(hx "$IFS")" IFS=: a=($pth) echo "Now this one works (because 'a' is already an array)" sho a echo "though IFS still got thrashed:" echo "IFS=$(hx "$IFS")" echo -n "resetting: " rs echo "IFS=$(hx "$IFS")" # so IFS works locally with assignment, but gets trashed. # shouldn't: # 1) local assignment work w/echo and 'let' # 2) shouldn't IFS remain untrashed with the 1 case # it does split properly (assignment)?