My original post did not show up properly. I am trying again.
I have a simple tsch script that does some basic arithmetic. The calculated value was not producing the result I was expecting. I wrote a sample script to illustrate the things that I tried.
#!/bin/tcsh
@ count = 43
@ total_count = 61
@ failing = 4
@ no_finish = 0
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = $total_count - $count - $failing
echo $no_finish
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = $total_count - ( $count + $failing )
echo $no_finish
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = ( $total_count - $count - $failing )
echo $no_finish
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = ( $total_count - $count ) - $failing
echo $no_finish
script output
Total Count:61 Finished:43 Failed:4 61-43-4
22
Total Count:61 Finished:43 Failed:4 61-43-4
14
Total Count:61 Finished:43 Failed:4 61-43-4
22
Total Count:61 Finished:43 Failed:4 61-43-4
14
Neo
January 3, 2014, 3:50pm
2
Send send me a PM with the code you just posted.
We are trying to debug some issue with some new software from DragonByte.
I cannot send a PM. I am a new user and do not have enough posts to qualify to send personal messages.
Steve
It seems to evaluate right to left, a - b - c is push c, negate, add b, negate, add a. Yes, it is ugly. Use parens. I installed tcsh just to try:
$ tcsh -c '@ a = 61
@ b = 43
@ c = 4
@ tot = $a - $b - $c
echo $tot'
14
$ tcsh -c '
@ count = 43
@ total_count = 61
@ failing = 4
@ no_finish = 0
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = $total_count - $count - $failing
echo $no_finish
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = $total_count - ( $count + $failing )
echo $no_finish
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = ( $total_count - $count - $failing )
echo $no_finish
echo "Total Count:$total_count Finished:$count Failed:$failing $total_count-$count-$failing"
@ no_finish = ( $total_count - $count ) - $failing
echo $no_finish
'
Total Count:61 Finished:43 Failed:4 61-43-4
14
Total Count:61 Finished:43 Failed:4 61-43-4
14
Total Count:61 Finished:43 Failed:4 61-43-4
14
Total Count:61 Finished:43 Failed:4 61-43-4
14
$ tcsh --version
tcsh 6.17.06 (Astron) 2011-04-15 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,nd,color,filec
$
Some called it a documented feature, but I think that is a stretch: Unix shell - View topic - Arithmetic in (t)csh : right to left ???