Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-10-2009
Registered User
 

Join Date: Sep 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
$1 $2 $3 error !!!

Hi All,

i need to use $1 , $2 etc..

but 1,2 ,3 etc must be dynamic.

example:


Code:
     say=5
        i=2
    toplam=0
    while [ $say -gt 0 ]
    do
        let toplam=toplam+$$i
    let say=say-1
    let i=i+1
    echo "toplam=$toplam"
   done


i remarked error word with red colour.


i tried it like "${$i}" and "$($i)" but also i took ERROR again

what can i do?

Thanx

---------- Post updated at 08:28 AM ---------- Previous update was at 08:27 AM ----------

bye the way, this code is in function and i give arguman to function.
But argumans are dynamic.

Last edited by pludi; 12-10-2009 at 08:41 AM.. Reason: code tags
Sponsored Links
  #2  
Old 12-10-2009
Registered User
 

Join Date: Mar 2008
Posts: 2,204
Thanks: 5
Thanked 40 Times in 39 Posts
See the "shift" command in your shell manual. You can then refer to each of the 5 parameters to the function as $1 .
I guess that you are trying to add up the 5 parameters to the script.


Code:
say=5
i=2
toplam=0
while [ $say -gt 0 ]
do
      let toplam=toplam+$1
      let say=say-1
      let i=i+1
      echo "toplam=$toplam"
      shift
done

./scriptname 1 2 3 4 5
toplam=1
toplam=3
toplam=6
toplam=10
toplam=15

./scriptname 99 42 63 87 174
toplam=99
toplam=141
toplam=204
toplam=291
toplam=465

  #3  
Old 12-10-2009
Registered User
 

Join Date: Sep 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Thanx so much my friend methly.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fssnap error :snapshot error: File system could not be write locked aggadtech08 Solaris 2 09-15-2009 10:12 AM
Build Error: error: dereferencing pointer to incomplete type katwala UNIX for Dummies Questions & Answers 8 04-17-2009 09:16 AM
Kernal panic error& setuproot:error mounting /proc&/sys arjunreddy3 Linux 2 03-09-2009 11:10 PM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 10:16 AM
Error: Internal system error: Unable to initialize standard output file firkus UNIX for Dummies Questions & Answers 2 10-25-2005 03:23 PM



All times are GMT -4. The time now is 07:36 AM.