11-14-2007
Quote:
Originally Posted by
haze21
#!/bin/csh
# This program will add integers
#
#
# add integer1 ..
#
# Check for argument
if ($#argv == 0 ) then
echo "usage: add integers"
exit 1
else
set input = $argv[*]
endif
#
set sum = 0
foreach var ( $input )
@sum = $sum + $input
end
#
echo "The sum total of the integers is $sum"
#
exit 0
#
Hi I am trying to make a program that adds all integers that are input.
ex. add 2 sum = 2
add 2 4 10 sum = 16
This is what i have for code but i keep getting the error "add: syntax error at line 18: `(' unexpected". If anyone could help me fix it i would appreciate it.
I would like to say that I came across same problem in SH script yesterday only .
https://www.unix.com/shell-programmin...ote-array.html
#!/bin/csh -f
echo 'enter a line'
set userline = $<
echo $userline
set sum = 0
foreach var ( $userline )
@sum += $var
end
echo "The sum total of the integers is $sum "
suppose you enter 3 4 5
it will give you 12
I am not sure !! is it helpful for you or not?
Quote:
Originally Posted by
haze21
What am I doing wrong with this foreach loop?
foreach var ($argv)
@sum = $sum + $var
As a rule in csh script
Integer calculations can be performed by C shell, using C language-type operators. To assign a calculated value, the @ command is used.
So, here we are trying to calculate . so we need "@" command instead of "$"
User_prady
Last edited by user_prady; 11-16-2007 at 12:52 AM..
10 More Discussions You Might Find Interesting
1. Filesystems, Disks and Memory
shell script for sorting,searchingand insertion/deletion of elements in a list (1 Reply)
Discussion started by: jayaram_miryabb
1 Replies
2. Programming
hi
I want to call a shell script in C program
the script is : ssh -t user@remote sh /<remote>home/user/<file_name>.sh
and other several commands
C program : Call this script and the retrive the task that is been done in <file_name>.sh file
can any one tell me how... (5 Replies)
Discussion started by: mridula
5 Replies
3. Shell Programming and Scripting
Hi,
Could anybody please let me know how to call a C_Program
from shell script. I know through command "system" we can call
shell script from C program.
Awaiting response.
Thanks and regards,
Chanakya M (4 Replies)
Discussion started by: Chanakya.m
4 Replies
4. Shell Programming and Scripting
Hi,
I wanted to write a schell program that fetches the values from a file and prints the output as its onerall multiplication.
for example I have a file named abc. it has values 2, 3, 4
now my program should give me 2*3*4 ie 24.
note:this file abc can have any numbers.
so experts,... (9 Replies)
Discussion started by: sandeep.krish
9 Replies
5. Shell Programming and Scripting
Hi there, im new too shell scripting and was wondering if it is possible to create a shell script to take in a variable and load a c program.
My C program is a file monitor, and is started by using the terminal and using to following code
./monitor FileToBeMonitored
is it possible to have... (12 Replies)
Discussion started by: gazmcc182
12 Replies
6. Shell Programming and Scripting
Hi,
I have a little problem...I want to do the following things:
Have my own little script that has 2/3 functions and starts a c++ application using some parameters.
The problems appear when I start the c++ app using the shell script, the c++ takes over and after I ctrl+c the script... (0 Replies)
Discussion started by: valiadi
0 Replies
7. Shell Programming and Scripting
shell script in Unix/Linux to find the lines numbers of a text file are having word which is 5 to 10 characters long and having first letter as a capital letter. (3 Replies)
Discussion started by: usersnehal
3 Replies
8. Shell Programming and Scripting
I followed the directions here
Free Twitter Source Code ? Twitter Database Server: Install
and created a php script that enters twitter keyword searches into a MySQL DB.
When you execute the files outlined in the above link, a script starts indefinitely.
I've noticed that the scripts... (6 Replies)
Discussion started by: phpchick
6 Replies
9. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Write the a shell script program to remove all space characters stored in the shell variable TEXT.... (7 Replies)
Discussion started by: kofine05
7 Replies
10. Shell Programming and Scripting
Hi I am new in programming.
I have written a shell code, but i want to secure my code.
I have tried SHC. It is converting it to binary, but can be converted in plain text again by core dump.
I have tried to convert it in rpm by "rpmbuild -bb my.spec" option but the result is same.
... (4 Replies)
Discussion started by: Priy
4 Replies
sum(1) User Commands sum(1)
NAME
sum - print checksum and block count for a file
SYNOPSIS
sum [-r] [file...]
DESCRIPTION
The sum utility calculates and prints a 16-bit checksum for the named file and the number of 512-byte blocks in the file. It is typically
used to look for bad spots, or to validate a file communicated over some transmission line.
OPTIONS
The following options are supported:
-r Use an alternate (machine-dependent) algorithm in computing the checksum.
OPERANDS
The following operands are supported:
file A path name of a file. If no files are named, the standard input is used.
USAGE
See largefile(5) for the description of the behavior of sum when encountering files greater than or equal to 2 Gbyte ( 2**31 bytes).
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of sum: LC_CTYPE, LC_MESSAGES, and
NLSPATH.
EXIT STATUS
The following exit values are returned.
0 Successful completion.
>0 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Availability |SUNWesu |
|CSI |enabled |
+-----------------------------+-----------------------------+
SEE ALSO
cksum(1), sum(1B), wc(1), attributes(5), environ(5), largefile(5)
DIAGNOSTICS
"Read error" is indistinguishable from end of file on most devices; check the block count.
NOTES
Portable applications should use cksum(1).
sum and usr/ucb/sum (see sum(1B)) return different checksums.
SunOS 5.10 7 Nov 1995 sum(1)