-1

Using the command line, I've defined two variables

set a = 5
set b = 5

In addition I've set another variable, c, in which I am trying to assign a's and b's value.

I tried -

set c = $($a+$b)

But I've got Illegal variable name.

I tried -

set c
c = $($a+$b)

But I've got Illegal variable name., again.

Alex Goft
  • 1,114
  • 1
  • 11
  • 23

3 Answers3

2
  • Set variable and assign value:

    @ a = 5
    

    This is same as:

    set a = 5
    
  • See value of the variable:

    echo $a
    

You may try following way:

    @ a = 4
    @ b = 5
    @ c = $a + $b

    echo $c
    9

Don't forget @, it's used instead of 'set'

You can have some basic ideas about working in tcsh from this site

PS. Never worked in tcshso please take my answer/suggestion with a pinch of salt.

Hasan Rumman
  • 577
  • 1
  • 6
  • 16
1

Change your script to:

a=5
b=4

c=$(($a + $b))
# test
echo $c
# prints 9

Note that double parenthesis and the removal of the set keyword.

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • But if im trying to write in command line `a=5`, i get `a=5: Command not found.`. That's why i used set. – Alex Goft May 07 '17 at 08:13
  • @AlexGoft Set doesn't do what you think. Also, maybe you had a space between the left and the right sides of the "=", which shouldn't be there. – Maroun May 07 '17 at 08:14
  • 1
    @MarounMaroun Turns out the question is actually about tcsh, not bash. – melpomene May 07 '17 at 08:58
  • @melpomene I think in this case it should be posted as a new question, since this one already has an answer and was tagged bash for a while. – Maroun May 07 '17 at 09:09
1
set a = 5
set b = 5
set c = `expr $a + $b`
JDQ
  • 111
  • 4