0

I'm writing a script in csh (it needs to be in csh) and I've really been struggling on what seems like a trivial problem. I want to set an environment variable with string containing a numeric variable. However I want to increment the value being stored without affecting the value. Is this possible. I've spent quite a while digging through csh tutorials and I'm at a loss. Below is the last iteration of what I have tried. Nothing seems to work.

set LOG_HIST = 8
setenv LOG_FILE "/foo/log/foo."${LOG_FILE}".log"
setenv NEXT_LOG_FILE "/foo/log/foo."(${LOG_FILE} + 1)".log"
1

1 Answer 1

3

You can use the backticks to get the output of a command and use expr to evaluate an arithmetical expression:

% set LOG_HIST = 8
% setenv LOG_FILE "/foo/log/foo."${LOG_HIST}".log"
% setenv NEXT_LOG_FILE "/foo/log/foo."`expr ${LOG_HIST} + 1`.log
% echo $NEXT_LOG_FILE
/foo/log/foo.9.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.