csh arithmetic ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting csh arithmetic ?
# 1  
Old 01-08-2010
csh arithmetic ?

Hello,

Could someone explain how this one is possible:
Code:
# @ x = 10 - 11 + 3
# echo $x
-4

I know that writing script using csh is bad idea, but I need to write few lines.

thanks
Vilius
# 2  
Old 01-08-2010
Not sure, but csh must be evaluating from right to left in which case 11+3 is calculated first and the 10 - result. something similar to this.

Code:
 
@ x = 10 - (11 + 3)

# 3  
Old 01-08-2010
Hi.

I think:

Code:

@ x = (10 - 11) + 3

gives the right result.

Csh Programming Considered Harmful

Top 10 Reasons not to use the C Shell
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arithmetic with bash

I need to divide the number of white spaces by total number of characters in a file using bash. I am able to get the number of white spaces correctly using: tr -cd < afile | wc -c I am also able to get the total number of characters using: wc -c afile How do I divide the first... (2 Replies)
Discussion started by: ngabrani
2 Replies

2. Shell Programming and Scripting

Csh arithmetic not producing the expected value

My original post did not show up properly. I am trying again. I have a simple tsch script that does some basic arithmetic. The calculated value was not producing the result I was expecting. I wrote a sample script to illustrate the things that I tried. #!/bin/tcsh @ count = 43 @... (3 Replies)
Discussion started by: sgualandri
3 Replies

3. Shell Programming and Scripting

arithmetic from csh variable passed to awk

I have the following code in a csh script I want to pass the value of the variable sigmasq to the awk script so that I can divide $0 by the value of sigmasq grep "Rms Value" $f.log \ | awk '{ sub(/*:*\.*/,x); \ print... (2 Replies)
Discussion started by: kristinu
2 Replies

4. UNIX for Dummies Questions & Answers

Arithmetic: how to??

Hello all, I'd like to know how to perform arithmetic on multiple files. I have got many tab-delimited files. Each file contains about 2000 rows and 2000 columns. What I want to do is to to sum the values in each row & column in every file. The following explains what I want to do; ... (9 Replies)
Discussion started by: Muhammad Rahiz
9 Replies

5. Shell Programming and Scripting

Arithmetic on timestamps

Hi Friends, please advise on shell script to add two time stamps for example : a=12:32 b=12:00 c=a+b=00:32 please help me to find shell script to add to two time stamps, as i need to convert time from EST to GMT or SST to prepare status of jobs in unix and to specify estimated time to... (3 Replies)
Discussion started by: balireddy_77
3 Replies

6. UNIX for Dummies Questions & Answers

Arithmetic Operators

Hello, I have a list of 'inputs' and i want to convert those on the second list named 'Desired Outputs', but i don't know how to do it? Inputs Desired Outputs 1 2 94 4 276 8 369 10 464 12 ... (0 Replies)
Discussion started by: filda
0 Replies

7. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

8. Shell Programming and Scripting

arithmetic in tcsh

Yes I know tcsh sucks for scripting and arithmetic but I have to write a script for multiple users and they all use tcsh. I have this variable that I 'set' with but pulling numbers off of stings with set STUFF = `grep string file | awk command` Now I would like to add up the numbers that... (4 Replies)
Discussion started by: gobi
4 Replies

9. Shell Programming and Scripting

Help with arithmetic operation

I am using egrep to extract numbers from a file and storing them as variables in a script. But I am not able to do any arithmetic operations on the variables using "expr" because it stores them as char and not integers. Here is my code and the error I get. Any help will be appreciated. #!/bin/sh... (3 Replies)
Discussion started by: emjayshaikh
3 Replies

10. UNIX for Dummies Questions & Answers

Arithmetic In UNIX

I am a beginner and I have been searching the web all morning for this answer but can't find it anywhere. I know that prtint 1*2 will return 1*2 what if i actually want the problem to be calculated so i want print 1*2 to return 2 How is this done? (3 Replies)
Discussion started by: tygun
3 Replies
Login or Register to Ask a Question