I'm new to shell scripting and I'm trying to read some code I need to use. Could you help me out on what it's doing? I read this as.... if the directory has files then rm all the files in that directory. I'm not sure....
if [ -f ${TSP_FILEPATH_PLUGIN_DIR} ]; then
run "rm -rf ${TSP_FILEPATH_PLUGIN_DIR}";
fi
run "mkdir -p ${TSP_FILEPATH_PLUGIN_DIR}";
I read ( but its the end of the day... and had very strange annoying support...) :
If there is a file callled {TSP_FILEPATH_PLUGIN_DIR} , then remove it with all if exist subdirectories and content (???) but could make sense if JAVA code ... (links to directory...even so, I doubt: why use -f rather than -e?) badly written to me...
run (?) mkdir -p {TSP_FILEPATH_PLUGIN_DIR} (create with correct path to subdirs where necessary...)
If ${TSP_FILEPATH_PLUGIN_DIR} is a directory, you would need -d not -f . A directory will never match -f .
if [ -d ${TSP_FILEPATH_PLUGIN_DIR} ]; then
This will not tell you if there are files in the directory, it will just tell you if the directory exists.
Footnotes:
1) I have go through life without ever needing rm -rf in a script. As a minimum, when testing your script consider echoing the command rather than executing it.
2) In unix scripting it is never necessary to end a line with a single semi-colon character.
Hypothetically what would the -f option perform on a directory. When I replace -f with -e some internal files within the directory are deleted (or at least they aren't shown), but when I keep the -f option those files remain in the directory. I need to keep the files (the are part of the framework of the server I'm using) so I will have to use the -f option.
Re post #7. Are you talking about if or rm ?
Please give an example.
The rm -rf directory is pretty ruthless. It deletes the directory named and all the contents.