![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
need help with a shell script
How do I store an argument as a string in the script?
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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?
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Try changing this line:
Code:
total=$(( $total + $(grep -c $n $2) )) |
|
#5
|
|||
|
|||
|
Also you need a space between [ and $#, and 2 and ] in the while statement.
|
|
#6
|
|||
|
|||
|
I tried those and the terminal says:
n="pattern: command not found total=0: command not found while: expression syntax |
|
#7
|
|||
|
|||
|
Are you sure it's running in bash? How are you executing it exactly? And what OS are you running under?
|
|||
| Google The UNIX and Linux Forums |