views:

74

answers:

2

I need to open a file using c shell. The file contains a single integer, and I need to put it into a variable, increase it and put back into the file. Meaning, if the file contains the number 5, I need, after the program runs, that the file contains the number 6. Any suggestions?

+1  A: 

You can use the @ command to evaluate it as numeric expression.

% echo 100 > test.txt
% set f = `cat test.txt`
% echo $f
100
% @ f = $f + 1
% echo $f
101
% echo $f > test.txt
% cat test.txt
101
Pasi Savolainen
worked perfectly. Thank you :)
n00b programmer
A: 

Or this:

expr `cat /tmp/X` + 1

(those are backquotes).

xcramps