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
convert the below perl sript to shell script mail2sant Shell Programming and Scripting 1 04-04-2008 02:36 PM
Shell Sript jazz8146 UNIX for Dummies Questions & Answers 3 01-11-2008 02:07 PM
how to assign sql output data to shell script variable kattics Shell Programming and Scripting 1 07-07-2006 04:57 PM
spell checker program ksjanakan Shell Programming and Scripting 2 05-21-2005 01:15 AM
Shell script syntax checker handak9 Shell Programming and Scripting 2 07-16-2004 04:56 AM

Closed Thread
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
  #1 (permalink)  
Old 11-09-2007
ccfc1986 ccfc1986 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 14
Shell Sript - Spell Checker Assign

Hi Folks. I am currently working on a script that has to spell check a file and print the output to the screen in 2 columns like this.

INCORRECT CORRECTION
whio who
weahter weather

The file will allow the user to override the ispell command and save any 'incorrect' words as 'correct' into a memory file which would then be used in any other runs of the script (as a dictionary file).

The code i currently have has a problem with it... and i cant figure it out for the life of me. Here is the code/script that i have written so far.


Code:
#!/bin/sh
# script that will spell check a file

#if user tries to quit, will say so, then quit on second attempt
trap "echo You are trying to exit; exit" 2


array=`ispell -l -p $HOME/memory.txt < $1`

correct=()
incorrect=""
let counter=1

for i in $array; do
        read -p "$i is mispelled. Press "Enter" to keep spelling, or type a correction here: " correction
        if [[$correction=""]] ; then
                echo $i >> $HOME/memory.txt
        else
                $correct[$counter]=$correction
        fi
let counter+=1
done

#prints the information
echo "CORRECTION       INCORRECT"
let count=1
for i in $array; do
        echo ${correct[$count]}        $i
let count+=1
done
For this code i get this output while runing:


sh-3.1$ ./wordspell testfile
hellio is mispelled. Press Enter to keep spelling, or type a correction here: hello
./wordspell: line 14: [[hello=]]: command not found
./wordspell: line 17: [1]=hello: command not found
whio is mispelled. Press Enter to keep spelling, or type a correction here: who
./wordspell: line 14: [[who=]]: command not found
./wordspell: line 17: [2]=who: command not found
wheter is mispelled. Press Enter to keep spelling, or type a correction here: weather
./wordspell: line 14: [[weather=]]: command not found
./wordspell: line 17: [3]=weather: command not found
CORRECTION INCORRECT
hellio
whio
wheter

I was wondering how i could sort out the line 14/17 errors. I have thought it would be something like missing () or {} in the array. But still no luck. Any ideas? Also, as you can see i want to print the correction, and the incorrect word (i have 2 arrays set, correct and incorrect which should contain the words for each). How would i get them to print out in columns like i have shown? Once i have this, i have another couple of things to code which im unsure of, but i will try after i get thsi first obstacle out of the way.

Thanks in advance
  #2 (permalink)  
Old 11-09-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,428
Code:
        if [[ "$correction" = "" ]] ; then
                echo $i >> $HOME/memory.txt
        else
                correct[$counter]=$correction
        fi
Jean-Pierre.
  #3 (permalink)  
Old 11-09-2007
ccfc1986 ccfc1986 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 14
Quote:
Originally Posted by aigles View Post
Code:
        if [[ "$correction" = "" ]] ; then
                echo $i >> $HOME/memory.txt
        else
                correct[$counter]=$correction
        fi
Jean-Pierre.
I attempted what you have given me, and it just gives me the exact same error messages (plus .... you aren't supposed to have spaces in your ##### = #### parts should be ####=#### right?)

Hope some advice still comes in, thanks for your time!
  #4 (permalink)  
Old 11-09-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,428
You execute your script with /bin/sh (line #1) which doesn't reconize the [[ ... ]] form of test.
You must use bash or ksh or replace [[ ... ]] by [ ... ]

There is no problem with spaces around the = operator.

Jean-Pierre.
  #5 (permalink)  
Old 11-09-2007
ccfc1986 ccfc1986 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 14
Cheers- but still...

Quote:
Originally Posted by aigles View Post
You execute your script with /bin/sh (line #1) which doesn't reconize the [[ ... ]] form of test.
You must use bash or ksh or replace [[ ... ]] by [ ... ]

There is no problem with spaces around the = operator.

Jean-Pierre.
Thank you Jean-Pierre for your persistence in regard to my problem. It is very much appreciated. My problem still stands, even with changing the #! line to /bin/bash .

I still get this:


sh-3.1$ ./wordspell testfile
hellio is mispelled. Press Enter to keep spelling, or type a correction here: hello
./wordspell: line 14: [[hello=]]: command not found
./wordspell: line 17: [1]=hello: command not found

Its got something to do with the arrays for sure - i have no idea why tho.

I might be thinking arrays too much like C++ arrays if that helps. lol. Anything is worth a look right?
  #6 (permalink)  
Old 11-09-2007
Lakris Lakris is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 246
Quote:
if [[ "$correction" = "" ]] ; then
evaluates to
Quote:
if [[ hello= ]] ; then
and that is not a valid test. Try
Quote:
if [[ x"$correction" = x"" ]] ; then
instead,just to avoid problems with comparisons without something to compare with.

/Lakris
Closed Thread

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 09:29 PM.


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