How to open a file that contains a single digit in C shell
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开发者_如何学JAVA the number 5, I need, after the program runs, that the file contains the number 6. Any suggestions?
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
Or this:
expr `cat /tmp/X` + 1
(those are backquotes).
精彩评论