Forum Moderators: bakedjake

Message Too Old, No Replies

Writing a Shell Script And Executing

Urgent Need Help Asap?

         

shimeekapayne23

5:56 pm on Dec 9, 2004 (gmt 0)

10+ Year Member



I AM WRITING A SHELL SCRIPT FOR MY CIS 105 UNIX COURSE AND I NEED HELP WRITING IT. IT WROTE WHAT THINK GOES IN THE SCRIPT BUT NEED ADDITIONAL HELP!

HERE ARE THE DIRECTIONS AND PSEUDOCODE GUIDE:
CREATE A SCRIPT THAT WILL DUPLICATE THE EFFECT OF THE rm -i command in a user friendly screen design. The script should tell what action has been taken. Use the following pseudocode as a guide:
TITLE
Deleting a file interactively
DESCRIPTION
This is the outline for deleting:
Get the filename from command line

If there is no file with that name
Print error message (File not found)
Otherwise
Ask if the user wants to delete the file
Read the user's choice (y/n)
If the choice is yes (y)
Remove the file and print a message
(File removed)

PLEASE HELP DUE MONDAY HERE'S A MY SCRIPT:

echo "Deleting a file Interactively"
echo
sleep 2
echo "Enter a filename:\c"
read answer
if [ "filename" ]
then
echo "Are you sure you want to delete this file?"
fi
echo "Input y for yes or no for no:\c"
read answer
if test "answer" = y
then
echo "File removed"
else
echo "File not Removed"
fi
echo
exit 0

MattyMoose

5:55 pm on Dec 13, 2004 (gmt 0)

10+ Year Member



I'm pretty sure that the implications of you asking for this level of help for a project are pretty serious. If you don't understand something as simple as this, how will you be able to cope with the assignments and expected knowledge in later segments?

PLEASE HELP DUE MONDAY HERE'S A MY SCRIPT:

Maybe you should've asked for help earlier, and not asked for a straight out answer. I also don't think anyone's going to do your homework and projects for you.

I'm going to not give you the answers, even though this is due today, apparently, but I'll point out the line numbers that need some attention.

1: echo "Deleting a file Interactively"
2: echo
3: sleep 2
4: echo "Enter a filename:\c"
5: read answer
6: if [ "filename" ]
7: then
8: echo "Are you sure you want to delete this file?"
9: fi
10: echo "Input y for yes or no for no:\c"
11: read answer
12: if test "answer" = y
13: then
14: echo "File removed"
15: else
16: echo "File not Removed"
17: fi
18: echo
19: exit 0

Code: Line 5, 6, 14
Logic: lines 7-10, 12,

A few notes:
Your logic is way messed up. When you ask them if they want to delete this file, it's in an if statement, then you break out of the if to see what the answer is. and continue on. If the file doesn't exist, it gives no warning and continues on and echoes "Input y for yes or no for no".

What if they input "Y" or "yes" in the "Input y for yes or no for no", you still want to work with users who don't read so well and allow for that. You best bet is switch/case.

You're not actually deleteing the files, and you're not checking the return status of rm. Also, your program returns exit status 0 no matter what happens.

You've got a lot of work to do to catch up to the level that they're asking for. It's not that hard to do this stuff, it just takes practice for the most part, and good google skills.

You may want to look here: [steve-parker.org...]

That's for bourne shell programming, but it's pretty much portable to bash.

HTH and good luck.