Results 1 to 6 of 6
I need a script that can be executed in its directory to delete the directory and its contents.
I tried using something like...
$bash ./folder/del-script.sh
Code:
#!/bin/rmdir
echo "If this ...
- 10-15-2007 #1
A script that can be executed in its directory to delete the directory and its ...
I need a script that can be executed in its directory to delete the directory and its contents.
I tried using something like...
$bash ./folder/del-script.sh
It didn't delete the script, the directory, nor its contents....Code:#!/bin/rmdir echo "If this show, then it probably wasn't deleted." exit 0
What do I have to do to create a script like that?
- 10-15-2007 #2
This didn't work:
This did work:Code:wally:~/monday/2/two$ cat 2.sh #!/bin/sh rm -rf . wally:~/monday/2/two$ ls -lR .: total 8 -rwx------ 1 wally wally 21 Oct 15 15:24 2.sh drwx------ 2 wally wally 4096 Oct 15 15:23 zwei ./zwei: total 0 wally:~/monday/2/two$ 2.sh rm: cannot remove `.' or `..' wally:~/monday/2/two$
Hope this helps.Code:wally:~/monday/2/two$ cat 2.sh #!/bin/sh xxx=`pwd` cd .. rm -rf $xxx wally:~/monday/2/two$ ls -lR .: total 8 -rwx------ 1 wally wally 42 Oct 15 15:27 2.sh drwx------ 2 wally wally 4096 Oct 15 15:23 zwei ./zwei: total 0 wally:~/monday/2/two$ 2.sh wally:~/monday/2/two$ ls -l total 0 wally:~/monday/2/two$ cd .. wally:~/monday/2$ ls -l total 40 -rwx------ 1 wally wally 42 Oct 15 15:27 2.sh -rw------- 1 wally wally 415 Oct 15 15:26 t1 -rw------- 1 wally wally 432 Oct 15 15:28 t2 wally:~/monday/2$
- 10-16-2007 #3
It somewhat hurt more than it helped.
It deleted the ./Desktop folder and whatever else what inside of the home folder.
Not cool.
Perhaps because I had made it one of the following:
rm -rf ./
rm -rf .
rm -rf
I had put the script into $HOME/testing/
I executed it from $HOME, I think...
I did that, because if I executed it inside of $HOME/testing/, then the folder wasn't destroyed... odd, but that's what happened.
I can't remember which one of the three. I know two didn't work, so I used one of them... can't remember much when everything I just had was recently deleted and I didn't see it coming...
Anyway, luckily, I was using an Ubuntu Live-CD, so things are alright.
Perhaps giving more details about what I'm trying to do will help.
Alright, so it's like this.
Scripts:
1. mkdir.sh
2. tasks.sh
3. copy.sh
4. execute.sh
mkdir.sh
tasks.sh *note: This is just an example...Code:#!/bin/sh mkdir ./1/ mkdir ./2/ mkdir ./3/
copy.shCode:#!/bin/sh echo "bark"
execute.shCode:#!/bin/sh cp ./tasks.sh ./1/ cp ./tasks.sh ./2/ cp ./tasks.sh ./3/
Now, what I want to do, is insert some commands into the tasks.sh script.Code:#!/bin/sh cd ./1/ bash tasks.sh cd .. # cd ./2/ bash tasks.sh cd .. # cd ./3/ bash tasks.sh cd ..
After it echos "bark," I want the script to delete the folder it is inside of. I also want the script to delete itself plus the contents of the folder it is inside.
The idea is that after all tasks.sh scripts are done executing, I will be left with the main directory.
- 10-16-2007 #4
In your detailed example, in each case you will be setting the "current directory" to be the same directory as the one containing the script.
In that case, my original solution should work quite well.
- 10-16-2007 #5
I see. I was being ignorant.
I didn't use the xxx, because I figured it had something to do with passwords.
Because I'm using a Live-CD, I ignored it.
I'm not too sure what the xxx stuff was all about.
Regardless, I used the cat print-out verbatim and turned it into a script.
It did work, so thanks.
Now, I just need to try it again to check for validity.
- 10-16-2007 #6
Quoth Agent-X:
I was going to use zzz, but I was afraid I'd fall asleep.I didn't use the xxx, because I figured it had something to do with passwords.


Reply With Quote