set: Variable name must begin with a letter

30.3k Views Asked by At

Its my code, how to set k as 17 less than j. It gives the error: set: Variable name must begin with a letter.

#! /bin/csh -ef

    set j =  18
    while ($j <= 40)
    set k = $j-17
    set i = 18
    while ($i <= 40)
    set l = $i - 17
        echo $i $j|gmx mindist -f 10ns_bit_45deg_LC3-v2.xtc -s for_prod2_POPC_24LC3-45deg.tpr -n LC3_protein_index.ndx -xvg none -od distance_p$l-LC3p$k.xvg -o distance_p$l-LC3p$k.out
    #   echo 17 14|g_dist -f ../../combined_trr/comb_10micro_LC3_310_1136lipids_MDSIM$j.trr -s ../cgmdsim1_1mer_LC3_310K_1136lipids.tpr -n GLP_a286.ndx -xvg none -o dist_protein_POPC_traj$j.xvg 
    #   awk ' { print $1, $5 }' dist_glp_protein_POPC_traj$j.xvg >zaxisdist_glp_protein_POPC_traj$ju.xvg

@ j++
@ i++

    end

exit -1
3

There are 3 best solutions below

0
On

Try this: @ k = $j - 17 Because you use subtract operation so you must use @

0
On

I'm not sure why you're getting that particular error message

set: Variable name must begin with a letter.

csh's syntax isn't particularly well defined, and the parser can become confused.

But the problem is that

 set l = $i - 17

will not perform subtraction. The correct syntax is:

@ l = $i - 17

Another problem: you have 2 while lines in your script, but only one corresponding end -- an error that would have been easier to find if you had used consistent indentation.

0
On

For tcsh ,I think the space after variable is the problem

set xyz ="asd" --> gives the same error 

set xyz="asd"  --> work all well