This is one of the most perennially important questions. How to effectively script ? What are the bad ways and what are the good ways ? I know of some, which i will point out here. If anybody does know of something else, kindly do leave a comment for the same. This question has been asked to know about the best practices available. It's very difficult to google everything and always all the things do not appear in the same place. Hence, this question has been asked to all of you experienced guys. I am myself trying to learn these things. Hence, i think any comments/answers that you guys provide here will be very helpful for me and people like me. Thanks in advance .
closed as not constructive by jw013, rush, Mat, warl0ck, Michael Mrozek♦ Oct 15 '12 at 14:20
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.
1.There is no need to define directory trees individually :
Bad Way :
Good Way :
2. Archiving :
Sometimes i have seen people move any tar like a.tar to another directory which happens to be the directory where they want to extract the archive. But that's not needed , as the -C option can be used here to specify the directory for this purpose.
3. Importance of control operators :
Suppose there are two commands, but only if the first command runs , then the second one must run, otherwise the second command would have run for nothing . So , here a command must be run, only if the other command returns a zero exit status.
In the above example, the contents of the archive need to be extracted in the directory : c, but only if the directory exists.If the directory does not exist, the tar command does not run, so nothing is extracted.