The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
invoking a shell script inside cgi shell script smriti_shridhar Shell Programming and Scripting 2 07-08-2008 10:50 PM
Accessing variables of one shell script in another shell script looza Shell Programming and Scripting 2 06-30-2008 04:13 PM
To call/execute a shell script from a shell script konark UNIX for Dummies Questions & Answers 1 10-26-2007 02:16 PM
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 1 04-30-2007 05:43 AM
Have a shell script call another shell script and exit heprox Shell Programming and Scripting 2 11-20-2006 05:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-12-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
need help with a shell script

How do I store an argument as a string in the script?
Reply With Quote
Forum Sponsor
  #2  
Old 10-12-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 920
Arguments are avaialble in a script as $1, $2, etc. You can just assign them to another variable if you wish to store them with a more meaningful name, e.g. OUTPUTFILE=$1. Is that what you mean?
Reply With Quote
  #3  
Old 10-12-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Yes, I tried that.
I'm writing a script to count the total number of occurrences in files entered as arguments with $1 as the pattern.
Here's what I have:

#!/bin/bash

n="$1"
total=0
while [$# -ge 2]; do
sed "s/$n/$n\n/g" $2
total=$[total+(grep -c $n $2)]
shift
done
echo $total


and it's not working.
Thanks
Reply With Quote
  #4  
Old 10-12-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 920
Try changing this line:

Code:
total=$(( $total + $(grep -c $n $2) ))
Reply With Quote
  #5  
Old 10-12-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 920
Also you need a space between [ and $#, and 2 and ] in the while statement.
Reply With Quote
  #6  
Old 10-12-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
I tried those and the terminal says:
n="pattern: command not found
total=0: command not found
while: expression syntax
Reply With Quote
  #7  
Old 10-12-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 920
Are you sure it's running in bash? How are you executing it exactly? And what OS are you running under?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0