Copy variable to array
Johnny Rosenberg
gurus.knugum at gmail.com
Sun Jun 1 22:10:58 UTC 2014
2014-06-01 19:02 GMT+02:00 Tony Arnold <tony.arnold at manchester.ac.uk>:
> On 01/06/14 17:47, Johnny Rosenberg wrote:
>
> I have a variable that contains a path. Now I want to copy every single
> directory to an array like this:
> x=./abc/def/ghi/jkl/mno
> # Do something here to copy x to the array y…
> echo ${y[3]} # Should print ”def”.
>
> Here's the result of my best (?) try:
> $ x="./abc/def/ghi/jkl/mno"; IFS='/'; y=$x; echo ${y[0]}; echo ${#y[@]};
> IFS=$'\n'
> . abc def ghi jkl mno
> 1
> $
>
> Try this instead:
>
> x="./abc/def/ghi/jkl/mno"; IFS='/'; y=($x); echo ${y[*]}; echo ${#y[@]};
> IFS=$'\n'
>
> For me, this produces:
>
>
> . abc def ghi jkl mno
> 6
>
>
Yes, I found out eventually. Thanks for replying.
Seems like ${y[*]} is the same thing as ${y[@]}, by the way.
Johnny Rosenberg
> Regards,
> Tony.
>
> --
> 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: tony.arnold at manchester.ac.uk
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20140602/59c7f1ae/attachment.html>
More information about the ubuntu-users
mailing list