Sorry for the delay, I went to the store and came back to find allot of very nice posts. After thinking about it, if the first number happens to end in *99,
FIRST_NUMBER='199'
then I would want 299 for my second number and not a repeat of 199.
So I guess this code will do what I need,
SECOND_NUMBER=$((((FIRST_NUMBER+1)/100+1)*100-1))
I plugged this into my script and I am getting the behavior I expect.
Is there some reason why my thought of just replacing the last two chars is ill conceived? The code I posted didn't work and I was getting a substring expression < 0 error.
I guess what I would have done here would have been to test $FIRST_NUMBER,
to make sure I didn't end up in the same place, but it is nice to do this in one step.
The negative value is only possible in bash 4. Probably your bash is too old..
But even with bash 4 it would be a problem if FIRST_NUMBER is a single digit..
Of course the value would still need to be corrected by one..
Last edited by Scrutinizer; 09-05-2014 at 06:13 PM..
All of the responses so far are assuming that the OLD_NUMBER is non-negative. If OLD_NUMBER can be less than -99, it is a little more complicated, but I think this works:
When put into a loop like this:
and invoked as:
with either bash or ksh, it produces:
Hello everyone.
I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)
Can such Puzzle solve through UNIX script? if yes, what could be the code?
This has been solve in C language. we were trying to solve this through shell but could not because of not able to pass 1st argument with multiple value. we are not expert in unix scripting. Below is the puzzle
John is a... (4 Replies)
Hi,
Here is the issue. From the program snippet I have Base: 0x1800000000, Size: 0x3FFE7FFFFFFFF which are of 40 and 56 bits. SO I used use bignum to do the math but summing them up I always failed having correct result.
perl interpreter info,
perl, v5.8.8 built for... (0 Replies)
Hi! All
Just wondering if anyone has a idea about setting the immutable bit
on a Solaris 10 ZFS file
I tried this
chmod S+ci toto.txt
and got that :-(
chmod: ERROR: invalid mode (0 Replies)
Hi ,
I am having file permision as
drwxrwsr_x
I kwo for deleting a file in the diretory i need w permsion as well ..
Say if i am having the permsion as
drwxrwsrwx - wil any one can delete the files in the directory ..
And one more question what is the s doing there ..... (2 Replies)
Hi All ,
I'm trying to do a simple math expression ...but unsuccessfull :-(
Anyone can help me?
days=23
amount=`expr ${days} / 30 \* -125`
echo $amount
but as result i got 0 when i expect 95.833333
Another question...how i can limit only to two or three decimal fields?
Thanks in... (1 Reply)
hello:
First I know the rules on Homework related questions,
I wrote my script, but I cannot seem to figure out how to do one math problem.
How do I take a zip code and seperate the idvidual digits?
I used the modulus expression and divided the number by 10 ^ n
but that only worked... (9 Replies)