0

I am trying to understand passing two variables from one csh script to another csh script. Perform simple arithmatic function then passing the sum variable to the orginal csh script. Then outputing the sum variable to standard output and a file.

script1.sh

#!/bin/csh
setenv num1 3
setenv num2 2
source script2.sh
set total=$sum
echo $total > total.txt
echo $total

script2.sh

#!/bin/csh
set int1=$num1
set int2=$num2
set sum=$int1 + $int2

1 Answer 1

1

With 'csh', the 'set' command perform simple (string) assignment, and takes a single word. The assignment 'set sum=$int +$int2' has 2 issues

  • It does not use a single word
  • Even the expression was combined into a single word (set sum="$int1 + $int2"), the set does not evaluate expression.

Consider instead using the '@' command which will take an expression

@ sum2 = $int1 + $int2

Sde note: For 'csh' script, the common convention is to use a '.csh' suffix. The '.sh' suffix is commonly used to files associated with sh-like shells (sh, bash, ash, ...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.