LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2007, 12:15 PM   #1
kromer12345
LQ Newbie
 
Registered: Jun 2007
Posts: 1

Rep: Reputation: 0
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
 
Old 06-27-2007, 12:25 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
I think I understand your question --> http://tldp.org/LDP/abs/html/internal.html#SOURCEREF

Last edited by weibullguy; 06-27-2007 at 12:38 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exercise Logging Software Jonititan Linux - Software 3 03-16-2007 11:20 PM
Exercise: Life Without Oil rvijay General 61 08-13-2005 01:01 PM
help with this exercise njeri Programming 1 04-26-2005 07:35 AM
Exercise 1-9. Write a program to copy its input to its output, replacing each string zombi3 Programming 3 12-21-2003 02:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration