Find the answer to your Linux question:
Results 1 to 3 of 3
i have been working on this script to add phone numbers to a source file... i have the script written and working but if a user makes a mistake it ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    3

    cant get the functionality i need...

    i have been working on this script to add phone numbers to a source file... i have the script written and working but if a user makes a mistake it will not jump to the previous line to correct the mistake.. i have tried several different things and cant get it to work... any help would be awesome...

    #!/bin/bash
    #================================================= =======
    # Script Name: phoneadd
    # By:
    # Date:
    # Purpose: A shell script that sets up a loop to add
    # new employees to the corp_phones file.
    # Command Syntax: phoneadd
    #================================================= =======
    trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
    phonefile=./corp_phones
    looptest=y
    while [ $looptest = y ]
    do
    clear
    tput cup 1 4 ; echo "Corporate Phone List Additions"
    tput cup 2 4 ; echo "=============================="
    tput cup 4 4 ; echo "Phone Number: "
    tput cup 5 4 ; echo "Last Name : "
    tput cup 6 4 ; echo "First Name : "
    tput cup 7 4 ; echo "Middle Init : "
    tput cup 8 4 ; echo "Dept # : "
    tput cup 9 4 ; echo "Job Title : "
    tput cup 10 4; echo "Date Hired : "
    tput cup 12 4; echo "Add another? (y)es or (q)uit "
    tput cup 4 18; read phonenum
    if [ "$phonenum" = 'q' ]
    then
    clear ; exit
    fi
    tput cup 5 18 ; read lname
    tput cup 4 18 ; read phonenum
    tput cup 6 18 ; read fname
    tput cup 7 18 ; read midinit
    tput cup 8 18 ; read deptno
    tput cup 9 18 ; read jobtitle
    tput cup 10 18; read datehired

    # Check to see if last name is not blank before you
    # write to disk
    if [ "$lname" > " "]
    then
    echo "$phonenum:$lname:$fname:$midinit:$deptno:$jobtitl e:$datehired" >> $phonefile
    fi
    tput cup 12 33 ; read looptest
    if [ "$looptest" = 'q' ]
    then
    clear ; exit
    fi

  2. #2
    Just Joined!
    Join Date
    Nov 2008
    Location
    Virginia, USA
    Posts
    18
    If you made a function for reading the input, then check for a certain keypress after each iteration of it. Then if you get that keypress you reverse the iteration.

    Code:
    function get_input {
        x=$1
        y=$2
        prompt=$3
        
        tput cup $y $x
        echo -n  $prompt
        read input
    
        return $input
    }
    Hopefully I didn't mix any perl in there but you should be able to move back and forth through a list of prompts based on what this function returns each time. As far as formatting it on the console the way you like, that'll take a little more work.

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    65
    Code:
    if [ "$looptest" = 'q' ]
    then
    clear ; exit
    fi
    u don't need this part at the end of teh code , just will be replaced by
    Code:
    done
    for what u are asking , i donno but u can make as follows , u can add another looptest called edit , so u will have 3 choices , edit , enter & quit

    the difference between enter and edit will be as follows :
    enter will insert into the file , edit will not
    enter will clear screen , but edit will not

    edit will make u go through the loop as if nothing happen , u will find ur words as it is , and u can edit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...