defensive Bash scripting
Hi guys,
How do i start off my Bash script to check to see if the file im interested in(which is automatically generated by another service) is actually there and if not there how can i tell the it to stop the execution of the rest of the script and echo something like file or directory not found? in BASH. Thanks in advance! |
Code:
-- test (use in a shell script to check to see if a given statement is true) |
Code:
if [[ ! -f filename ]]; then |
see "man test" also :)
|
Code:
if [[ -f filename ]]; then |
That's done your homework for you!!
|
of course I (we, others) have to take into account you may not know anything about programming whatsoever.
Introduction |
Quote:
You have done some bash scripting, as shown in your other question http://www.linuxquestions.org/questi...9/#post5718425, therefore I urge you to post your code here, or better describe what you have reviewed or tried. As I mentioned in that other thread, here are a few bash reference links: Bash Guide for Beginners Advanced BASH Scripting Guide My Bash Blog Note that in Bash Beginners guide will tell you lots about file tests for things like making a determination as to whether a file exists and if it is a regular file or a directory. Please take the time to review these or other references for Bash. I feel that if you persist with asking open ended questions, you'll possibly get confusing information back with members sometimes attempting to provide you wish some potentially useful code clips. |
Quote:
I did workup this exercise for shits and giggles. Code:
touch LQRocks |
I don't think I said too much because he still needs to figure out what (besides the shebang and whatnot) in order to get that to work in that if statement?
Quote:
Code:
[[ ! -f LQRocks ]] && echo "Not found" || (echo Exists ; rm LQRocks) Note: why you got rm LQrocks when it returns that it is not there I do not know. of if it is then what takes place by the way you have it written? @rtmistler Oh I didn't realize it was that guy. I just looked at the link you gave to that page to reference his other post .... I don't find myself paying attention to the poster name, I look more at the problem presented. |
Thank you guys for your responses. greatly appreciate it. This is a huge community and i am very happy for that. Also, rtMistler, I will post in the right forums. Sorry beginners mistake.
thanks again guys!!! |
Quote:
|
Quote:
File test operators Exit and Exit Status |
Quote:
|
Quote:
Thanks! This is pretty straight forward! gracias compadres! |
All times are GMT -5. The time now is 12:51 PM. |