开发者

How to open a file that contains a single digit in C shell

开发者 https://www.devze.com 2022-12-27 16:48 出处:网络
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 th

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号