![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SU issues | yoi2hot4ya | Shell Programming and Scripting | 1 | 10-09-2007 12:11 PM |
| Tar issues! HELP! | Slaughter | UNIX for Dummies Questions & Answers | 3 | 04-19-2006 01:22 PM |
| Issues with cut | bthomas | Shell Programming and Scripting | 1 | 09-08-2005 01:43 PM |
| AIX 5.3 Issues | miket | AIX | 1 | 04-26-2005 06:12 PM |
| dns issues | rickyt00 | UNIX for Advanced & Expert Users | 1 | 03-22-2005 11:18 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Variable issues
Hey guys, I have just started getting into shell scripting, ive been self educating myself with it and have run into a snag. I am trying to make a very simple addition script. The script would be passed a number of parameters (numbers) and it would add them all together. I can do this fine when there is a set number of parameters but when they are undefined I have trouble. Here is what I have so far and its output. Code:
#!/bin/csh if ( $#argv <= 1 ) then echo Usage: 2 parameters are required exit 1 endif echo $#argv numbers were entered set totalparameters = $#argv @ sum = $1 + $2 while ($totalparameters > 0) shift @ totalparameters -- @ sum = $sum + $2 echo $sum end Code:
robert-desktop:~/bin> argvexample 1 2 3 2 4 numbers were entered 6 8 @: Expression Syntax. robert-desktop:~/bin> It is adding the numbers but its throwing an error. Im totally lost. If you can help I would really appreciate it. Thanks in advance. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|