little confusion about variable initialization.
Whenever i execute the below scriptlet with out proper file name it deletes /tmp directory .
I guess this is because value of variable a didnt get initialized and there for rm -rf /tmp/ get executed and entire /tmp directory get deleted. How would i avoid any empty variables to be used in script? as this is a classic case of destructive script. Code:
#!/bin/bash |
Maybe you should do a man test (test being the same as using [) and then look for which test checks if a files exists.
Also, always try your commands at the command line prior to using them in a script to see what the result is. |
I have modified the code . Please share your views on the modified script.
Code:
#!/bin/bash |
like this
Code:
#!/bin/bash |
You probably already knew this, and I don't want to insult you, but being as this is in the newbie forum I figured it couldn't hurt to mention that the rm -rf command can be pretty dangerous. Especially when dealing with user input (doubly so if that user has full privileges). Your system will quite happily delete your OS if you tell it to. For and example of this (and a laugh) I suggest you watch this video.
|
Quote:
Code:
#!/bin/bash |
You said "Enter file or folder", but rm without the -r option will not delete directories.
|
Quote:
|
Use the -r option.
|
All times are GMT -5. The time now is 08:30 AM. |