Variable substitution in tcsh

0

Need your help. I've gone through the manual for the tch but still can't figure out how it should work in my case or whether it should work at all. I basically need to extract part of the variable whose value is a six digit number. So I need to drop the first two characters and
retrieve the last four. The example below doesn't work (it would probably work in bash but tcsh HAS to be used):

set VAR1 = value1

set VAR2 = echo ${VAR1:2}

echo VAR2

It comes up with error "Bad : modifier in $ (2)". Apparently, that's coz its bash syntax and not understandable by tcsh, but can't figure out how to do it with tcsh arguments.

Dmitry Erin

Posted 2014-09-04T13:54:08.947

Reputation: 1

Answers

0

that is bash syntax you are using, for tcsh it should be

$VAR1:s/1/2/

johnshen64

Posted 2014-09-04T13:54:08.947

Reputation: 4 399

Thanks, but it's not exactly what I need. This way it just replaces all 1's with 2's regardless of their position within the variable. But I need to replace the first two characters regardless of their value. I need the offset, not the value. – Dmitry Erin – 2014-09-05T18:04:14.963