+ Reply to Thread
Results 1 to 2 of 2

Thread: Unix Shell Programming

  1. #1
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Unix Shell Programming

    hi, i'm new at unix and am writing a program to classify data into data types (str, int, float); however, everytime i try to run it for debugging purposes, i get an error.

    the error is:
    Code:
    ./data_type.bash: line 72: syntax error: unexpected end of file
    the program is:
    Code:
    #!/bin/bash
    #
    # data_type
    # by: james brumond
    #
    # used for determining the data type of a string.
    # returns one of the following:
    #         [str | int | float]
    #
    # when used with the -s option, it can be used to
    # change an int or float into a str.
    #
    # exit status codes:
    #       64 - improper option use
    #
    
    helpMsg="data_type\nby:james brumond\nused to assign and determine data types.\n\
    available data types for use are: [str | int | float]\n\n\
    format for this command is:   data_type [variable name] [options]\n\n\
    options:\n-s:type       manually sets the data_type of a variable to type\n\
    -h      displays this help message\n\n\
    typing this command with no options but with a valid variable name\n\
    will echo the data_type of the variable."
    
    if [ "$#" -eq 0 ]
    then
            echo "$helpMsg"
            exit 0
    elif [ "$#" -eq 1 ]
    then
            if [ "$1" = -h ]
            then
                    echo "$helpMsg"
                    exit 0
            else
                    # auto type set
                    dataType="$?"
                    if [ "$dataType" -eq 65 ]
                    then
                            echo "str"
                            exit 0
                    elif [ "$dataType" -eq 66 ]
                    then
                            echo "int"
                            exit 0
                    elif [ "$dataType" -eq 67 ]
                    then
                            echo "float"
                            exit 0
                    fi
            fi
    elif [ "$#" -eq 2 ]
    then
            if [ "$2" != -s:* ]
            then
                    exit 64         # incorrect option use
            else
                    # manual type set
                    dataType="$?"
                    if [ "$dataType" = 65 ]
                    then
                            echo "str"
                            exit 0
                    elif [ "$dataType" = 66 ]
                    then
                            echo "int"
                            exit 0
                    elif [ "$dataType" = 67 ]
                    then
                            echo "float"
                            exit 0
                    fi
    please help!

  2. #2
    vol7ron's Avatar
    vol7ron is offline x10 Lieutenant vol7ron is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    DC
    Posts
    434

    Re: Unix Shell Programming

    u need two more "fi"s in there to close the outer two if statements.
    If you find my post useful please add to my reputation by clicking the +Rep button
    You may also use the Donate link to donate credits - this is appreciated too Thanks to those whom have donated so far!


+ Reply to Thread

Similar Threads

  1. Common Programming Terms --- Part II
    By Tariqul Islam in forum Tutorials
    Replies: 2
    Last Post: 08-14-2008, 01:10 AM
  2. Common Programming Terms --- Part I
    By Tariqul Islam in forum Tutorials
    Replies: 2
    Last Post: 01-19-2008, 12:08 AM
  3. Setting up Mail / Web / Shell with Fedora.
    By Starshine in forum Off Topic
    Replies: 3
    Last Post: 10-11-2006, 09:39 PM
  4. Root and Shell Access
    By Wai_Wai in forum Free Hosting
    Replies: 5
    Last Post: 09-09-2005, 01:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers