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"
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