Yes/No Then Follow Command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Yes/No Then Follow Command
# 1  
Old 06-01-2009
Yes/No Then Follow Command

Hello Guys,

I'm currently creating a script for a couple of things and I'm semi stuck on where to go next.

This is the script i've written but its not working in the exact way i want it to work.

#!/bin/bash

while :
do
clear
echo " M A I N - M E N U"
echo "1. Make a New Directory"
echo "2. Safely Delete a File"
echo "3. List Out the Contents of a File"
echo "4. Display the Full name of Any User"
echo "5. Display The Current Date"
echo "6. Display the Disk Usage"
echo "7. Show who is logged on"
echo "8. Show User Processes"
echo "9. Display The logfile"
echo "0. Exit"
echo -n "Please enter option [0 - 9]"
read opt
case $opt in
1) echo "Make a New Directory, Enter a New DIR NAME please $USER";
read "dir_name";
mkdir $dir_name;
if [-d $dir_name];
then echo "$dir_name Has been created";
else echo "$dir_name Hasn't Been Created";
fi;;
2) echo "Please Type in a File that you want to delete";
read "fname";
echo -n "Do you want to Safely delete this file? $fname";
echo "...";
read "response";
if [ $response = "y"-o $response = "YES" -o $response = "Yes" ];
then rm -r $fname;
else
echo "File Not Deleted";
fi;;
# 3)
# 4)
# 5)
# 6)
7) echo "This Is Who Is Currently Logged";
who | more;;
# 8)
# 9)
# 0)

esac
done

My Problem is that when taking a response from option number 2 it will delete a file if there is any but won't continue to echo for a wrong response.
I also want to add an echo if the File has been deleted when u confirm to delete the file.

I would also respect it if there are ways to simplify this script, I'm a beginner at Shell Scripting and have picked it up quite fast so any basic that can be explained because im not likely to understand anything more advanced.

Thank you for any help Smilie
# 2  
Old 06-01-2009
Code:
rm -r $fname  2>/dev/null

if [ $? -eq 0 ] ;then
echo "file deleted"
else
echo "no such file"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. War Stories

Do you trust your users to follow your instructions?

This happened a long time ago and some of the details may not be exact. Customer had obsolete hardware running an obsolete SCO OS and some type of database program with data scattered around the system. There were 2-1g SCSI drives, both split in half, with the 3 filesystems automatically loading... (6 Replies)
Discussion started by: edfair
6 Replies

2. OS X (Apple)

Does MAC OSX follow POSIX?

i mean if i coded an application for Linux using System Calls and no libs, and compiled it on MAC, will it work? thanks (6 Replies)
Discussion started by: JonhyM
6 Replies

3. Linux

How to follow up disk mirroring process?

Hi, The OS is SuSE Enterprise 11 and the system is HP WS460c G6 Blade with hardware disk array RAID 1 mirror. One disk was just replaced and the disk mirroring process is on its way. My question is how to follow up / monitor the disk mirroring process? I know hpacucli can do the job, but there... (0 Replies)
Discussion started by: aixlover
0 Replies

4. UNIX for Dummies Questions & Answers

Not follow symbolic links with diff -r

Hallo, i want to compare 2 directories with diff -r. But i don't want to follow symbolic links. Any idea how to realize that? Thanks (1 Reply)
Discussion started by: schaaf
1 Replies

5. UNIX for Dummies Questions & Answers

follow-up question on passphrase and script

can i use key with passphrase on a script/batch process? i am not sure how to pass the pasphrase in the script. i'd like to automate secure file transfer. thanks in advance (0 Replies)
Discussion started by: NoelSacay
0 Replies

6. UNIX for Advanced & Expert Users

How to follow processes and their children with ps

Hi, I often need to find the child processes of a parent process. There may be a string of 4-5. That is, PPID 884 spawns 890, which spawns 894, which spawns 1017. I'd like to be able to see all of them without having to type in a number of ps -ef commands. Process groups and session ID's are... (2 Replies)
Discussion started by: mschwage
2 Replies

7. Shell Programming and Scripting

Follow-up w/ Perderabo re: mimetool

This is a follow-up re: this thread As I mentioned, this script works very nicely, thanks again. However, the ASCII data of the 'attached file' also shows below the body of the email message. Do you know of a way to 'disable' the attached text from showing? Although the file is attached,... (3 Replies)
Discussion started by: jwperry
3 Replies
Login or Register to Ask a Question