Sponsored Content
Top Forums Shell Programming and Scripting Csh arithmetic not producing the expected value Post 302882024 by sgualandri on Friday 3rd of January 2014 03:47:51 PM
Old 01-03-2014
Csh arithmetic not producing the expected value

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.

Code:
#!/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



Last edited by sgualandri; 01-03-2014 at 04:52 PM.. Reason: original text did not show up
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

#/usr/bin/csh -f not working as expected?

Hey everyone, A coworker of mine has written a csh script that starts with #!/usr/bin/csh -f. It's my understanding that the -f should skip the .cshrc and .login files, but here's the problem: In the script "line" is used, and I happen to have a "line" in my ~/bin. When the script is ran my... (4 Replies)
Discussion started by: effigy
4 Replies

2. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

3. Shell Programming and Scripting

sed in while loop producing arithmetic output

Hi all Just wondering if someone can help me with this. I'm trying to write a script that processes the output of another file and prints only the lines I want from it. This is only the second script I have written so please bare with me here. I have referred to the literature and some of the... (3 Replies)
Discussion started by: javathecat
3 Replies

4. Shell Programming and Scripting

Script not working...producing 0's and not number

Below is my script: #!/bin/sh #echo "Please type oracle-lower case please:" #read X #if ] #then # echo "Sorry that is not oracle, try again" # exit 1 #else # echo Thank you #fi find / -name oracle 2>/dev/null | while read line do bdf 2>/dev/null |... (6 Replies)
Discussion started by: bigben1220
6 Replies

5. Shell Programming and Scripting

csh arithmetic ?

Hello, Could someone explain how this one is possible: # @ x = 10 - 11 + 3 # echo $x -4 I know that writing script using csh is bad idea, but I need to write few lines. thanks Vilius (2 Replies)
Discussion started by: vilius
2 Replies

6. Shell Programming and Scripting

Help, while loop and sed not producing desired output

Hello everyone, I need some assistance with what I thought would have been a very simple script. Purpose of Script: Script will parse through a source file and modify (search/replace) certain patterns and output to stdout or a file. Script will utilize a "control file" which will contain... (12 Replies)
Discussion started by: packetjockey
12 Replies

7. Shell Programming and Scripting

arithmetic from csh variable passed to awk

I have the following code in a csh script I want to pass the value of the variable sigmasq to the awk script so that I can divide $0 by the value of sigmasq grep "Rms Value" $f.log \ | awk '{ sub(/*:*\.*/,x); \ print... (2 Replies)
Discussion started by: kristinu
2 Replies

8. IP Networking

Tcpdump -i any producing duplicate packages?

Hi, Can anyone explain why do I see same request twice in tcpdump package when I use "tcpdump -i any"? So I'm tracing packets on eth1.800 interface, but using "tcpdump -i any" to capture them. What I see is that the requests/responses from my side seem to appear as duplicate in the pcap file,... (1 Reply)
Discussion started by: Juha
1 Replies

9. Shell Programming and Scripting

awk producing too many fields

Hey guys, awk is putting out too many results, two of each specifically. See below. Code: read CPU_VENDOR_ID <<< $(cat /proc/cpuinfo | grep "vendor_id" | awk -F: '{print $2}') echo $CPU_VENDOR_ID echo Output: AuthenticAMD AuthenticAMD I only want it to print out "AuthenticAMD" once. ... (7 Replies)
Discussion started by: 3therk1ll
7 Replies

10. Shell Programming and Scripting

awk script not producing output

Hi, I have a text file with some thousands of rows of the following kind (this will be referred to as the inputFileWithColorsAndNumbers.txt): Blue 6 Red 4 Blue 3 Yellow 4 Red 7 Colors in the left column and a number in the right one for each line. I want to run an awk... (5 Replies)
Discussion started by: Zooma
5 Replies
project_walk(3PROJECT)													    project_walk(3PROJECT)

NAME
project_walk - visit active project IDs on current system SYNOPSIS
cc [ flag ... ] file... -lproject [ library ... ] #include <project.h> int project_walk(int (*callback)(const projid_t project, void *walk_data), void *init_data); The project_walk() function provides a mechanism for the application author to examine all active projects on the current system. The callback function provided by the application is given the ID of an active project at each invocation and can use the walk_data to record its own state. The callback function should return non-zero if it encounters an error condition or attempts to terminate the walk prema- turely; otherwise the callback function should return 0. Upon successful completion, project_walk() returns 0. It returns -1 if the callback function returned a non-zero value or if the walk encountered an error, in which case errno is set to indicate the error. The project_walk() function will fail if: ENOMEM There is insufficient memory available to set up the initial data for the walk. Other returned error values are presumably caused by the callback function. Example 1: Count the number of projects available on the system. The following example counts the number of projects available on the system. #include <sys/types.h> #include <project.h> #include <stdio.h> typedef struct wdata { uint_t count; } wdata_t; wdata_t total_count; int simple_callback(const projid_t p, void *pvt) { wdata_t *w = (wdata_t *)pvt; w->count++; return(0); } ... total_count.count = 0; errno = 0; if ((n = project_walk(simple_callback, &total_count)) >= 0) (void) printf("count = %u ", total_count.count); See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ getprojid(2), libproject(3LIB), settaskid(2), attributes(5) 7 Oct 2003 project_walk(3PROJECT)
All times are GMT -4. The time now is 11:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy