Why won't my Ksh do math with (( ))?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why won't my Ksh do math with (( ))?
# 1  
Old 10-12-2009
Why won't my Ksh do math with (( ))?

Hello,

I'm usring Ksh on AIX 5.3. For some reason my K-Shell gives me an error when I try to use the math operators (( )).

Can anyone tell me what's going on and how to fix it?

Thanks so much!

My K-Shell:
Code:
/>ls -al /usr/bin/ksh
-r-xr-xr-x   5 bin      bin          237420 Apr 10 2007  /usr/bin/ksh

Commands:
Code:
 
/>myvar=$ (( 1 + 1 ))
ksh: syntax error: `(' unexpected
 
/>myvar=`expr 1 + 1`
/>echo $myvar
2
 
/>let myvar=$ (( 1 + 1 ))
ksh: syntax error: `(' unexpected

# 2  
Old 10-12-2009
Hi.

What's with the space between $ and (

Remove that and try again.

Code:
x=1
x=$ ((x+1))
-ksh: syntax error: `((' unexpected
x=$((x+1)) 
echo $x
2

# 3  
Old 10-12-2009
I was following the example in this post. It looked like there was a space after the $ and before (( at first glance. It worked after I removed the space.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script won't run because hardware won't produce display

Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK... (3 Replies)
Discussion started by: yelirt5
3 Replies

2. UNIX for Dummies Questions & Answers

Math

i have file (my_file.txt) that looks like this: 000000000000010000 000000000000010000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 all said and one, it should look... (11 Replies)
Discussion started by: lawsongeek
11 Replies

3. Shell Programming and Scripting

ksh field math

Hi, I have a text like with many rows of data like: 7a,0,1182 7a,1,1040 7b,0,483 7b,1,242 7c,0,224 7c,1,877 I need to be able to take the value of the first field (i.e. 7a) and if there are multiples, add the value of the third field, (1182 + 1040) and insert the output of all of this in... (2 Replies)
Discussion started by: scriptr2be
2 Replies

4. Shell Programming and Scripting

Math action in ksh

Hello, I want to do div action in ksh and get the full result(with leftover). i.e. 4/3=1.33 and not 4/3=1 (4 Replies)
Discussion started by: LiorAmitai
4 Replies

5. Shell Programming and Scripting

ksh date math

I have a requirement to remove all files from a directory execpt those > (now -N hrs). Once I can figure out how to calculate (now -N hrs) I was thinking of creating a temporary file with that time (now-N hrs) than using the find and -newer option. Does anybody have any KSH code (needs to... (3 Replies)
Discussion started by: BeefStu
3 Replies

6. Shell Programming and Scripting

created a .alias, but they won't take (ksh)

I login with a common username, and have no access to the different login scripts for my personalizations. So for a while, I would hobble on over to a directory I made for myself, and then bring in my alias file where I would fix my backspace, create a few aliases, etc.: $ ./.alias $ Now... (4 Replies)
Discussion started by: hindesite
4 Replies

7. Shell Programming and Scripting

math help

$ x=1 $ y=1.5 $ z=$((x*y)) bash: 1.5: syntax error: invalid arithmetic operator (error token is ".5") What's wrong? (2 Replies)
Discussion started by: rockbike
2 Replies

8. AIX

won't mount /usr...won't boot fully

Hello: NOOB here. I attempted to use smit mkcd. Failed on first attempt, not enough space. 2nd attempt tried to place iso on /usr, not enough space there. Cleanup ran for about 5 minutes after aborting. Now AIX won't boot. LCD display on 7029-6E3 says: 0517 MOUNT /USR. Attempted to boot from CD... (11 Replies)
Discussion started by: bbird
11 Replies

9. UNIX for Dummies Questions & Answers

Ksh Why Won't IF Statement work?

I'm trying to figure out why this if statement won't work: if || $zipcount != 6 ]] then echo ${myline} echo "ZIPCODE WARNING! ${zipcode} ${zipcount}" fi if ]] then echo ${myline} echo "STATE WARNING!... (3 Replies)
Discussion started by: developncode
3 Replies

10. Programming

something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field I got header file <math.h> included in my .c file , then I write the code as below: k = sqrt(i); /* both variables k and i are int */ then I cc temp.c it says like this undefined... (4 Replies)
Discussion started by: blf0
4 Replies
Login or Register to Ask a Question