How to solve Subscript out of range?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to solve Subscript out of range?
# 1  
Old 03-24-2009
How to solve Subscript out of range?

Hi everyone
I want to compare numbers line by line
Example
array = 12 15 15 19 14

I have code:
Code:
#!bin/csh
set a = 1
set b = 2
while($a<6)
if($array[$a] == $array[$b])then
echo "EQUAL"
else if($array[$a] < $array[$b])then
echo "SMALLER"
else 
echo "BIGGER"
endif
@ a = $a + 1
@ b = $b + 1
end

Output:
Code:
SMALLER
EQUAL
SMALLER
BIGGER
Subscript out of range

Can explain to me why there is a Subscript out of range?
How to solve it?
Thks. =)
# 2  
Old 03-24-2009
I'm not familiar with csh but it seems that you're trying to access a non-existing element of the array (comparing array[5] with array[6]).

Regards
# 3  
Old 03-24-2009
Thks.
The problem is inside while( ) ,right?
if my no. of array is unlimited or unknown,
I should put what in while ( ) ?
Thks for your help =)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Calling subscript with sh vs. ksh

I ran into an issue today that I was able to resolve, but I don't quite understand why the resolution worked. I'm wondering if anyone can help me make sense of it. I have a "kicker" script that calls 4 subscripts on a RHEL 6.9 server. It calls the scripts in sequence checking for a 0 exit code... (5 Replies)
Discussion started by: derndingle
5 Replies

2. UNIX for Dummies Questions & Answers

Name of subscript

I have a script that executes another, so script1 executes script2. Using the $0 variable inside script2 returns the name of script1. How can I get the name of script2? Thanks (2 Replies)
Discussion started by: charding1
2 Replies

3. Shell Programming and Scripting

How to use a subscript and a super script while printing a character

I want to print a output after executing a awk command How to represent a subscript or a superscript while using print command eg : Ts. where character 's' is subscript of T T2 where '2' is the superscript of T thank you. Shashi: (3 Replies)
Discussion started by: shashi792
3 Replies

4. Shell Programming and Scripting

print range between two patterns if it contains a pattern within the range

I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated. e.g. Pattern1 Bombay Calcutta Delhi Pattern2 Pattern1 Patna Madras Gwalior Delhi Pattern2 Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies

5. UNIX for Dummies Questions & Answers

creating a subscript which checks for a flag?

I want to incorportae a subscript in a job script which is used for loading purposes. What i require is that before a job runs it should check for a flag ,if flag is not present then create it and the loading should start. Once loading finishes it should delete the flag. So if any other load... (3 Replies)
Discussion started by: bathla
3 Replies

6. Shell Programming and Scripting

checking for a flag in a subscript?

I want to incorportae a subscript in a job script which is used for loading purposes. What i require is that before a job runs it should check for a flag ,if flag is not present then create it and the loading should start. Once loading finishes it should delete the flag. So if any other load... (2 Replies)
Discussion started by: bathla
2 Replies

7. AIX

Checking for flag in a subscript?

I want to incorportae a subscript in a job script which is used for loading purposes. What i require is that before a job runs it should check for a flag ,if flag is not present then create it and the loading should start. Once loading finishes it should delete the flag. So if any other load... (1 Reply)
Discussion started by: bathla
1 Replies

8. UNIX for Advanced & Expert Users

Can somebody solve this

I have to find the files older than 200 days from a path and copy them to some other directory with the current date stamp attached to it. i have written like follows: #!/bin/ksh DSTAMP=$(date +"%y%m%d%H%M") rm $CA_OUT_PATH/ftp_logs/temp touch $CA_OUT_PATH/ftp_logs/temp chmod 777... (1 Reply)
Discussion started by: sreenusola
1 Replies

9. Shell Programming and Scripting

Perl hashes "Can't use subscript on private hash"

This is driving me mad, where am I going wrong? The relevant segment of code: sub getndsybcons { my @servers=@{$_}; my @sybservers=@{$_}; my %results; foreach my $server(@servers) { my $biggestsyb; my $biggestsybval=0; ... (9 Replies)
Discussion started by: Smiling Dragon
9 Replies

10. Shell Programming and Scripting

Calling subscript but sleep halts the main script

Ok, I have written a main script which checks a directory contents every 30 secs then sleeps. The subscript does a usermod, if the user is logged on, it sleeps for 30 secs and then trys again over and over again. Here's the problem. when the subscript is called ./subscript.sh or exec... (1 Reply)
Discussion started by: doublejz
1 Replies
Login or Register to Ask a Question