Need helpThis script erased a bunch of my files HELP
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need helpThis script erased a bunch of my files HELP
can anyone tell me why this script didnt prompt me for a CLA
or CD into the directory specified?? I,m using Cygwin for windows sdo I had to mkdir the cygdrive firrst then I ran this script in my home folder and it just started erasing emacs files and folders......Not my temporory internet files
Can someone help or tell me why it did this or give suggestions?
Code:
echo "would you like to delelte your temp internet files"
read yes
if [ $1 = yes ]
then
cd /cygdrive/c/Documents\ and\ Settings/Owner/Local\ Settings/Temporary\ Internet\ Files/
rm -rvf *
else
echo "fine let them sit there"
exit 1
fi
Whats a CLA? Command line argument? There isn't a prompt for command line arguments. Command line arguments need to be on the command line with the application name.
app_name arg1 arg2 etc. etc...
Did the script stop and wait with the read statement for you to enter something?
Also the if statement should be like for a command line argument:
if [ $1 = "yes" ] then
If you are trying to use the read statement then
if [ $yes = "yes" ] then
Your if statement is evaluating to true because you did not enter a command line argument and yes does not evaluate to anything.
I would guess that something is wrong with your cd statement. Since your current working directory was your home directory the rm will delete everything.
BTW hindsight is always 20-20 but try testing your script in some test directory where you can not do any damage.
if i'm right then $1 is the first argument after the command's name. that's the only way it can delete your files. read yes means it's reading the variable yes; but it isn't using it anywhere else.
echo "would you like to delete your temp internet files?"
read yes
case "$yes" in
[Yy]) rm -frv $TEMP_DIR;;
*) echo "fine let them sit there";
exit 1;;
esac
if you use your method, I would ensure you actually cd'd to the directory by checking the return value of the statement before you delete stuff. Your script deleted the stuff ASSUMING you were in the directory. Check the success two ways:
1. Use $? (the return code of a statement)
cd /tmp
if [ $? -eq 0 ] then
rm -fr *
fi
2. Use &&
cd /tmp && rm -fr *
The statement after the && will execute if the first statement is successful.
I was about to add te very same thing, but with this method of checking:
if `cd /path/to/change/to`
then do things
else
echo "Can't change dir"
fi
Also, trade14u, I played your Russian Roulette game, but it just kept saying "You live", and one time it didn't do anything, and then my pc crashed and it won't reboot to Linux.
thanks for all of your help, unfortunately none of your examples worked,
I tried the TEMP_DIR one, no avail? no output
After trying my script instead of erasing I tried
echo $PWD
it still says home/owner
and I dont know why????
I know I messed up it wasnt suppposed to have a CLA and my if variable was wrong i changed it to
read answer
if [ $answer = yes ]
then
/temp && rm -fr *
but that doesnt seem to want to work either??
Any ideas why its not CDing to that directory?????
Thanks for all the help
I know I messed up it wasnt suppposed to have a CLA and my if variable was wrong i changed it to
read answer
if [ $answer = yes ]
then
/temp && rm -fr *
but that doesnt seem to want to work either??
Is this code copied and pasted? If so then your problem is that you put
/temp
instead of
cd /temp
Although it still shouldn't have worked, since /temp should return negative since it's not a valid command. I assume you're using bash? Do echo $SHELL to find out.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.