Find the answer to your Linux question:
Results 1 to 2 of 2
Howdy, I’m doing some exercises for my Linux scripting class in preparation for a test and was doing well until I hit the last exercise which currently has me mind ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    1

    I need some help for a Linux exercise

    Howdy,

    I’m doing some exercises for my Linux scripting class in preparation for a test and was doing well until I hit the last exercise which currently has me mind boggled.

    Any help would be greatly appreciated.

    Ok, I need to insert the second script into the first one so that when trying to type d:3 for deleting the 3rd choice from the geeko file, I should be prompted with this: type y(es) or n(o)

    So basically the second code has to be inserted into first one but so far I’ve had no luck.

    Here is the first script:

    #!/bin/bash
    #finalize2.sh

    tinum=`cat /var/spool/mail/geeko | grep '#' | wc -l`

    if test $tinum -gt 10
    then
    echo -e "Welcome to the Request Tracker.\nThere are $tinum open requests. You have to do something!\a"
    else
    echo -e "Welcome to the Request Tracker.\nThere are $tinum open requests:\n"
    fi

    input='l'
    until test $input = "quit"
    do
    reqnr=1
    while read line
    do
    if echo $line | grep '#' > /dev/null
    then
    lines[$reqnr]="$reqnr|$line"
    ((reqnr++))
    fi
    done < /var/spool/mail/geeko

    com=`echo $input | cut -d ':' -f 1`
    req=`echo $input | cut -d ':' -f 2`

    case $com in
    'i') echo -e `echo ${lines[$req]} | cut -d '|' --output-delimiter='\n' -f '3 4 5 6'` ;;
    'l') for ((i=1;i<=${#lines[@]};i++))
    do
    echo -e ${lines[$i]} | cut -d '|' --output-delimiter=', ' -f '1 3 4 5'
    done
    ;;
    'd') rm /var/spool/mail/geeko
    for ((i=1;i<=${#lines[@]};i++))
    do
    if test $i -ne $req
    then
    echo ${lines[$i]} | cut -d '|' --output-delimiter='|' -f '2 3 4 5 6' >> /var/spool/mail/geeko
    else
    echo "Request $req deleted."
    fi
    done
    ;;
    *) echo "Unknown Command"
    esac

    unset lines
    read input
    done

    And the second:

    #!/bin/bash
    #Prompt the user to answer with "yes" or "no"
    #The question itselfis supplied as an argument
    #"When calling the function, for example?"
    while true
    do
    echo "$*"
    echo "Please answer by entering (y)es or (n)o:"
    read ANSWER
    case "$ANSWER" in
    [yY] | [yY][eE][sS] )
    return 0
    ;;
    [nN] | [nN][oO] )
    return 1
    ;;
    * )
    echo "I cannot undersand you over there."
    ;;
    esac
    done

  2. #2
    Linux Newbie objuan's Avatar
    Join Date
    Jul 2006
    Location
    california
    Posts
    218
    Hi
    have you tried using a include at the end of your script.

    include /path/filename

Posting Permissions

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