![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Add Item to Dock 0.0.8 | iBot | UNIX and Linux RSS News | 0 | 06-03-2008 05:10 AM |
| problem with array=($(find ....) | jul | Shell Programming and Scripting | 1 | 02-27-2008 04:28 PM |
| Add Item to Dock 0.0.7 | iBot | UNIX and Linux RSS News | 0 | 01-24-2008 08:40 AM |
| replace item.. | happyv | UNIX for Dummies Questions & Answers | 2 | 09-14-2007 12:09 AM |
| Skip item by using substring | rwunwla | Shell Programming and Scripting | 2 | 12-16-2005 01:12 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
find an available item in array
Dear all,
I'm have a sorted array like this: 177 220 1001 2000 2001 2003 2005 notice that 2002 and 2004 are NOT in array. Then user input a number INPUT, our script should return OUTPUT value like this: if INPUT is not in array => OUTPUT=INPUT if INPUT is in array => OUTPUT is the smallest number that larger than INPUT and should NOT exist in array! Example with this array: INPUT => OUTPUT 1000 => 1000 1001 => 1002 2000 => 2002 2005 => 2006 Can anyone help me to complete this on bash shell! |
|
|||||
|
Perhaps try something like this, which is at the bash prompt...
Code:
$ for v in 177 220 1001 2000 2001 2003 2005; do a[$v]=1; done
$ read -p "Input = " i; while [[ ${a[$i]} = 1 ]]; do ((i+=1)); done; echo Output = $i
Input = 2000
Output = 2002
Last edited by Ygor; 07-16-2007 at 01:41 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|