<div dir="ltr"><div>I have a variable that contains a path. Now I want to copy every single directory to an array like this:</div><div>x=./abc/def/ghi/jkl/mno</div><div># Do something here to copy x to the array y…</div><div>
echo ${y[3]} # Should print ”def”.</div><div><br></div><div>Here's the result of my best (?) try:</div><div>$ x="./abc/def/ghi/jkl/mno"; IFS='/'; y=$x; echo ${y[0]}; echo ${#y[@]}; IFS=$'\n'<br>
. abc def ghi jkl mno<br>1<br>$</div><div><br></div><div>Here's what I hoped would happen:</div><div><div>$ x="./abc/def/ghi/jkl/mno"; IFS='/'; y=$x; echo ${y[0]}; echo ${#y[@]}; IFS=$'\n'<br>
.<br>6<br>$</div><div><br></div><div>What am I doing wrong? It seems to work if I read the path from a file with ”read -r -a”, why not from a variable?</div><div><br></div><div><br></div><div>Johnny Rosenberg</div></div></div>