<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 01/06/14 17:47, Johnny Rosenberg wrote:<br>
</div>
<blockquote cite="mid:CADo7T4eUmjx8UC4aNvMtY39TofT2pi954T8fz9sL8TjVrENU9w@mail.gmail.com" type="cite">
<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>
</blockquote>
Try this instead:<br>
<br>
x="./abc/def/ghi/jkl/mno"; IFS='/'; y=($x); echo ${y[*]}; echo ${#y[@]}; IFS=$'\n'<br>
<br>
For me, this produces:<br>
<br>
. abc def ghi jkl mno<br>
6<br>
<br>
Regards,<br>
Tony.<br>
<pre class="moz-signature" cols="72">-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 705 344 3082
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: <a class="moz-txt-link-abbreviated" href="mailto:tony.arnold@manchester.ac.uk">tony.arnold@manchester.ac.uk</a>
</pre>
</body>
</html>