![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call C Program From Shell Script | Chanakya.m | Shell Programming and Scripting | 1 | 05-22-2008 10:40 PM |
| please convert the below program into shell script | mail2sant | Shell Programming and Scripting | 3 | 04-10-2008 05:39 AM |
| want to run different files under the same program using shell script | cdfd123 | Shell Programming and Scripting | 3 | 10-04-2007 12:27 AM |
| Calling SHELL script from C program | Chanakya.m | Shell Programming and Scripting | 7 | 09-21-2007 05:34 PM |
| shell script program | jayaram_miryabb | Filesystems, Disks and Memory | 1 | 03-09-2005 05:12 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help on C-shell script program
#!/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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Quote:
sh shell user input and stote it to a array #!/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:
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-15-2007 at 09:52 PM. |
|||
| Google The UNIX and Linux Forums |