Bizzare (while statement)


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Bizzare (while statement)
# 1  
Old 06-22-2006
Bizzare (while statement)

I'm trying to use the while statement to increment a positive number, with a leading "0". when I pass it through, it seems to come out with a negative value, and all the increments remain negative.

This is what I have:

i=010986294184
j=010986988888

while [ $i -lt $j ]; do
echo $i
i=(($i + 1))
done

The output i get is:
010986294184
-1898607703
-1898607702
-1898607701
-1898607700
-1898607699
-1898607698
-1898607697
-1898607696
-1898607695
-1898607694
......
.....

Does anyone have a clue why this is happening? The numbers increment quite satisfactrily once $i has become -ve, but why does it become negative?

Thanks
# 2  
Old 06-22-2006
take this,

Code:
#! /usr/bin/ksh

typeset -Z12 i

i=010986294184
j=010986988888

while [ $i -lt $j ]
do
echo $i
i=$(($i + 1))
done

exit 0

# 3  
Old 06-22-2006
It hasn't made any difference matrix
# 4  
Old 06-22-2006
it works perfect in ksh

what shell are u using ?
# 5  
Old 06-22-2006
Not every implementation of every shell has 64 bit arithmetic. Sometimes 32 bits is all you have.

Code:
$ bc
10886284184 % 2^32 - 2^32
-1998617704
$

# 6  
Old 06-23-2006
Hey its working fine wheni work at my end
# 7  
Old 06-23-2006
Quote:
Originally Posted by katoch_ravi
Hey its working fine wheni work at my end
Well, grats. You must be using a shell with 64 bit arithmetic. Here is what happens when you use a shell with 32 bit arithmetic...
Code:
$ i=010986294184
$ i2=$((i))
$ echo $i2
-1898607704
$ bc
10986294184 % 2^32 - 2^32
-1898607704
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

Bizzare behavior on redirect of stdout

Oracle Linux 5.6 64-bit (derivative of RHEL) Dear Ann Landers, This is about as bizarre as anything I've ever seen. I have a little test script I've been working with. When I redirect stdout to a file, no file. Make a copy of the script to another name. Execute it and redirect stdout, and... (4 Replies)
Discussion started by: edstevens
4 Replies

3. Programming

Bizzare optimization problem

I have a C program that, for the life of me, I can't see any possible stack corruption in but for some reason corrupts a local variable to 0 when not referenced. My compiler is gcc 4.3.4. But my question's not really a code question, it's a compiler question. The glitch is weirdly specific: ... (3 Replies)
Discussion started by: Corona688
3 Replies

4. UNIX for Advanced & Expert Users

Bizzare TCP/IP problem

Hi all. I have a really really weird problem that I've been working on for days. The problem manifested as users cannot connect to our web servers via SSH when they're using our wireless network. Here's where it gets weird: - Clients from anywhere other than the wireless subnet can... (4 Replies)
Discussion started by: pileofrogs
4 Replies

5. Shell Programming and Scripting

help with counting processes, bizzare behavior

I have a ksh script (dtksh Version M-12/28/93d on Solaris 10) that is run daily by cron and sometime hangs forever. I need to detect if there is an old copy hung before I start the new run, and if so send an email and exit the script. Here is part of the code: #!/usr/dt/bin/dtksh... (4 Replies)
Discussion started by: 73rdUserID
4 Replies

6. IP Networking

Bizzare network attack?

A server I host is having very rare glitches where a file the user downloads will have incorrect contents. This almost never happens when I am looking, I caught it once and only once -- a user messaged me saying his antivirus had given him a warning about an image file downloaded from his... (2 Replies)
Discussion started by: Corona688
2 Replies

7. Shell Programming and Scripting

If statement help

I'm trying to create a script that would allow me to identify the sucessful removal of a file. Here's what i put together so far, let me know if it's correct or not. FILE_NAME="cactus.dat" FILE_FIND='find / -name $FILE_NAME' if ;then echo "cactus.dat was not removed successfully" ... (3 Replies)
Discussion started by: sdpinoy
3 Replies

8. Programming

very bizzare file writing problem

I'm trying to write a function which opens a file pointer and writes one of the function parameters into the file, however for some reason Im getting a core dump error. The code is as below void WriteToFile(char *file_name, char *data) { FILE *fptr; /*disk_name_size is a... (10 Replies)
Discussion started by: JamesGoh
10 Replies

9. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

10. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies
Login or Register to Ask a Question