LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2016, 04:43 AM   #16
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73

Quote:
Originally Posted by robertjinx View Post
Your example doesn't fully work:


My example:
Nevermind, I'm blind and st*pid You are using *.txt. Sorry!
 
Old 10-28-2016, 05:49 AM   #17
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Did you notice from your example?
Code:
item 0: android : Audio <--
item 1: Audio<-- : bin <--
item 2: bin<-- : build <--
item 3: build<-- : Calibre
 
Old 10-28-2016, 08:02 AM   #18
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Quote:
Originally Posted by michaelk View Post
Did you notice from your example?
Code:
item 0: android : Audio <--
item 1: Audio<-- : bin <--
item 2: bin<-- : build <--
item 3: build<-- : Calibre
Not sure what you mean?
 
Old 10-28-2016, 08:19 AM   #19
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
You deleted your post but anyway.
Code:
i=0
next=0
for i in ${!a[@]}; do
	next=$(($i + 1))
	echo "item $i: ${a[$i]} : ${a[$next]}"
done
The script outputs values as below so you are repeating items.
item 0: a[0] : a[1]
item 1: a[1] : a[2]
item 2: a[2] : a[3]

One possible fix.
Code:
for (( i=0; i<${#a[@]}; i+=2 )); do
  next=$(($i + 1))
  echo "item $i: ${a[$i]} : ${a[$next]}"
done
 
Old 10-28-2016, 09:00 AM   #20
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Ahh, OK, thanks!
 
Old 09-19-2018, 10:28 AM   #21
new_user3085
LQ Newbie
 
Registered: Sep 2016
Posts: 21

Original Poster
Rep: Reputation: Disabled
Talking

Thanks a LOT (really! A LOT!!) for all your time. I'm so sorry I forgot that this post was kept open. robertjinx's script did what I was trying to do.


@Habitual..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Silly mistake in lftp bash script probably quotes emmalg Linux - Software 3 02-08-2013 05:12 AM
awk script: where is the mistake? lumacho Slackware 4 10-16-2009 08:39 PM
rc.4 script deleted by finger mistake Cuetzpallin Slackware 2 07-25-2008 09:42 PM
Script checking - what is my mistake? Riddick Linux - General 9 09-18-2005 03:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration