Find the answer to your Linux question:
Results 1 to 2 of 2
I have this project which I've been working on essentially nonstop for the past three days and due to work I am running low on time. I'm new to Linux/Unix ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2

    Question function questions (bash)

    I have this project which I've been working on essentially nonstop for the past three days and due to work I am running low on time. I'm new to Linux/Unix and my Teacher has assigned us a scripting project, due for Monday. I have All the functions for the project in a separate file which run as a daemon process when I log in. It has no syntax errors but my Script can not run the functions (I'm not sure where they go before or after the body) and I have one function I'd like you guys to take a look at. It has a Second menu leading to a case statement but it does not run after the Search. I'm Kinda tired of looking at the CLI but I have to finish this. Thanks.

    phoneEdi()
    {
    directory=~/phonepro/directory
    loop="y"
    clear
    tput cup 4 4; echo "Record Editor"
    tput cup 5 4; echo "============="
    tput cup 7 4; echo "Which record?"
    tput cup 8 4; echo "Search: "
    tput cup 8 12; read number || continue
    grep $number $directory | tr ':' ' ' > temp
    sed /$number/d $directory > f
    cp f $directory
    rm f
    grep $number $directory > temp
    A=`cut -f1 $temp`
    B=`cut -f2 $temp`
    C=`cut -f3 $temp`
    D=`cut -f4 $temp`
    E=`cut -f5 $temp`
    F=`cut -f6 $temp`
    G=`cut -f7 $temp`
    while [ $loop = "y" ]
    do
    clear
    tput cup 3 12; echo "Record Editor"
    tput cup 4 12; echo "============="
    tput cup 6 9; echo "F - First Name"
    tput cup 7 9; echo "L - Surname"
    tput cup 8 9; echo "P - Phone Number"
    tput cup 9 9; echo "A - Address"
    tput cup 10 9; echo "C - City"
    tput cup 11 9; echo "S - State"
    tput cup 12 9; echo "Z - Zip Code"
    tput cup 13 9; echo "Q - Quit"
    tput cup 15 4; echo "Edit Another? (y)es or (n)o"
    tput cup 13 25;
    read opt || continue
    case $opt in
    [Ff]) tput cup 6 25
    read B
    ;;
    [Ll]) tput cup 7 25
    read A
    ;;
    [Pp]) tput cup 8 25
    read C
    ;;
    [Aa]) tput cup 9 25
    read D
    ;;
    [Cc]) tput cup 10 25
    read E
    ;;
    [Ss]) tput cup 11 25
    read F
    ;;
    [Zz]) tput cup 12 25
    read G
    ;;
    [Qq]) exit ;;
    esac
    tput cup 16 9
    read loop
    if [ $loop = "n" ]
    then
    echo "$A:$B:$C:$D:$E:$F:$G" >> $directory
    fi
    done
    }

  2. #2
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2
    Sorry the second post was the same function for whatever reason here is the actual new function:
    phoneEdi()
    {
    directory=~/phonepro/directory
    clear
    tput cup 4 4; echo "Record Editor"
    tput cup 5 4; echo "============="
    tput cup 7 4; echo "Which record?"
    tput cup 8 4; echo "Search: "
    tput cup 8 12; read number || continue
    grep $number $directory | tr ':' ' '
    grep $number $directory > temp
    A=`cut -f1 -d $temp`
    B=`cut -f2 -d $temp`
    C=`cut -f3 -d $temp`
    D=`cut -f4 -d $temp`
    E=`cut -f5 -d $temp`
    F=`cut -f6 -d $temp`
    G=`cut -f7 -d $temp`
    loop=y
    while test $loop = y
    do
    clear
    tput cup 3 12; echo "Record Editor"
    tput cup 4 12; echo "============="
    tput cup 6 9; echo "F - First Name"
    tput cup 7 9; echo "L - Surname"
    tput cup 8 9; echo "P - Phone Number"
    tput cup 9 9; echo "A - Address"
    tput cup 10 9; echo "C - City"
    tput cup 11 9; echo "S - State"
    tput cup 12 9; echo "Z - Zip Code"
    tput cup 13 9; echo "Q - Quit"
    tput cup 15 4; echo "Edit Another? (y)es or (n)o"
    tput cup 13 25;
    read opt || continue
    case $opt in
    [Ff]) tput cup 6 25
    read B
    ;;
    [Ll]) tput cup 7 25
    read A
    ;;
    [Pp]) tput cup 8 25
    read C
    ;;
    [Aa]) tput cup 9 25
    read D
    ;;
    [Cc]) tput cup 10 25
    read E
    ;;
    [Ss]) tput cup 11 25
    read F
    ;;
    [Zz]) tput cup 12 25
    read G
    ;;
    [Qq]) exit ;;
    esac
    tput cup 16 9
    read loop
    if [ $loop = "n" ]
    then
    echo "$A:$B:$C:$D:$E:$F:$G" >> $directory
    fi
    done
    sed /$number/d $directory > f
    cp f $directory
    rm f
    }

Posting Permissions

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