Hidden syntax error somewhere

Ray Parrish crp at cmc.net
Wed Dec 9 20:08:00 UTC 2009


Hello,

I'm working on yet another script, and it's tossing an error that I 
cannot locate the cause of. Here is the error message -

/home/ray/Bashscripts/TestScriptlet.sh: line 273: syntax error near 
unexpected token `}'
/home/ray/Bashscripts/TestScriptlet.sh: line 273: `}'

The unexpected } is the one at the end of the function according to this 
error message.

And here is the script portion causing it -

# This function detects web urls in a line of text.

function DetectHttp {
     # Assign passed in values to a variable.
     ThisLine="$1"
     HttpStart=0
     # Check for existence of http in ThisLine.
     CharacterPosition=0
     while [[ $CharacterPosition -lt ${#ThisLine} ]]; do
           CharacterPosition=$(( $CharacterPosition + 1 ))
           # Get next character of ThisLine
           Character=${ThisLine:$CharacterPosition:1}
           case $Character in
               "h")
echo "HPos - $HPos"
                   HPos=$CharahterPosition
                   HChar="h";;
               "t")
                   if [[ "$TChar" == "t" ]]
                      then
                          T2Pos=$CharacterPosition
echo "T2Pos - $T2Pos"
                          T2Char="t"
                      else
                          TPos=$CharacterPosition
echo "TPos - $TPos"
                          TChar="t"
                   fi;;
               "p")
                   PPos=$CharacterPosition
echo "PPos - $PPos"
                   PChar="p";;
           esac
           if [[ "$HChar$TChar$T2Char$PChar" == "http" && $(( $PPos - 
$HPos )) -eq 3 && $TPos -gt $HPos && $T2Pos -lt $PPos  && $T2Pos -gt 
$TPos ]]
              then
                  HttpStart="$HPos"
echo "HttpStart - $HttpStart"
           fi
     done

     if [[ $HttpStart -gt 0 ]]
        CharacterPosition=0
        SpaceNumber=0
        then # Loop through string looking for spaces, and recording 
their positions.
            while [[ $CharacterPosition -lt ${#ThisLine} ]]; do
                  CharacterPosition=$(( $CharacterPosition + 1 ))
                  Character="${ThisLine:$CharacterPosition:1}"
                  case $Charachter in
                       " ")
                           SpacePositions[$SpaceNumber]=$CharacterPosition
                           SpaceNumber$(( $SpaceNumber + 1 ));;
                  esac
            done
            EndofURL=0
            # Loop through SpacePositions looking for a space that is 
past HPos.
            for Positions in ${SpacePositions[@]}; do
                    if [[ $Positions -gt $HPos && $EndofURL -eq 0 ]]
                       then
                           EndofURL=$(( $Positions - 1 ))
echo "EndofURL - $EndofURL"
                    fi
            done
            if [[ $HttpStart -gt 0 ]]
               then
                   LengthURL=$(( $EndofURL - $HttpStart ))
echo "Length = $Length"
                  URL=${ThisLine:$HttpStart:$LengthURL}
            fi
     echo "$URL"
}
# Main Program starts here.
Line="this is a test: http://www.rayslinks.com/index.html of if this works."
clear
DetectHttp "$Line"

I'm getting bleary eyed staring at this thing trying to figure ou what 
I've done wrong, and I cannot find the mistake. I'm hoping some 
additional eyes will spot what I'm doing wrong.

Thanks for any help you can be.

Later, Ray Parrish

-- 
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com






More information about the ubuntu-users mailing list