![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script for Deleting Core files on root filesystem | rgfirefly24 | Shell Programming and Scripting | 7 | 02-11-2008 02:41 PM |
| make script deleting mp3 with warnig to users | stefan | Shell Programming and Scripting | 2 | 11-24-2006 01:43 AM |
| Urgent help required in deleting a line without opening a file usinga shell script | naan | Shell Programming and Scripting | 6 | 07-20-2006 12:42 AM |
| shell script: deleting files from a directory | onlyc | Shell Programming and Scripting | 1 | 07-09-2006 03:41 AM |
| Deleting by ID | boyler | Shell Programming and Scripting | 1 | 09-23-2003 07:37 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a script like this called "remove.sh":
#!/usr/bin/ksh rm remove.sh echo "Deleted myself!" Since UNIX is a scripting language I thought running it like " sh remove.sh" would generate an error/ or ANYTHING except the echo statements output. But the echo statement came out alright! Since in this case I had spawned a sub-shell (using 'sh'), I tried running it as ". remove.sh" and it still worked. Can anybody explain why? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Put this in a script and run it. It will delete itself.
Code:
#! /bin/rm -f echo "This will never get printed...!" |
|
#3
|
|||
|
|||
|
Thanks a lot Vino!
Could you also tell me why the previous version (the one I posted ) works (I mean, gives the echo output). I had thought the shell scripts were executed line-for-line without being stored in a temporary buffer. |
|
#4
|
|||
|
|||
|
Because the interpreter (the shell) loads the whole script and then executes it line by line. It would be really rather ineficient for it to repeatedly read a line and execute that line.
|
|
#5
|
|||
|
|||
|
I tried the script by Vino. The line is getting printed and the file is not getting deleted. Im using OSF1 V5.1 732 alpha. I am using Korn Shell.
|
|
#6
|
|||
|
|||
|
It works fine for me ... how are you executing the file?
If you are calling it like: Code:
ksh remove.sh What do you have in your script and how are you involking it? |
|
#7
|
||||
|
||||
|
Quote:
More than that, despite the name, rm does not remove files, it unlinks them from directories. If the file has zero links and is not open by any process, it is removed. So the file will not disappear while ksh has it open. Instead, it becomes a file with zero file names. This behavior is a good way to handle temporary files and a lot of programs do that... create a file, unlink it, then use it. It is guaranteed to disappear upon program exit. Newbie admins post fairly often saying that a big file ate their filesystem, they deleted it, and they did not get the space back. This is why that happens. The file is still consuming space and will until the process that has it opened is killed. And now the file has no name so it is much harder to deal with. |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|