![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Remove & insertion of data in a same file | videsh77 | Shell Programming and Scripting | 10 | 03-01-2007 06:27 AM |
| automatic header insertion | olimiles | Shell Programming and Scripting | 4 | 08-22-2006 05:24 AM |
| problem with Unicode characters insertion | suman_jakkula | AIX | 0 | 02-11-2006 01:20 AM |
| Insertion of Leap Second | isingh786 | UNIX for Advanced & Expert Users | 2 | 12-28-2005 02:05 PM |
| Immediate Help With Sort | bernie | UNIX for Dummies Questions & Answers | 2 | 05-13-2004 05:36 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
insertion sort???
Hi, I was wondering if someone here could help me figure out what's wrong with this simple insertion sort shell script. This is the output I get when I try to run it: "23 43 22 15 63 43 23 11 10 2 ./insertion.sh: line 23: [: -gt: unary operator expected 2 63 63 63 63 63 63 63 63 63 63" The test file I use looks like this: Code:
23 43 22 15 63 43 23 11 10 2 And here's the script: Code:
#!/bin/bash
#read in the data from a file
echo "Enter file to be sorted: "
read file
a=1
while read myline; do
array[$a]=$myline
a=`expr $a + 1`
done < $file
#display the unsorted data
echo ${array[*]}
#sort the data
b=1
while [ $b -lt $a ]; do
index=${array[$b]}
c=$b
z=`expr $c - 1`
while [ $c -gt 0 ] && [ ${array[$z]} -gt $index ]; do
array[$c]=${array[$z]}
c=`expr $c - 1`
done
array[$c]=$index
b=`expr $b + 1`
done
#display the sorted data
echo ${array[*]}
Last edited by Yogesh Sawant; 04-15-2008 at 02:31 AM.. Reason: added code tags |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|