The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-24-2008
bert682 bert682 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 2
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0