![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Basic Java Persistence API Best Practices | iBot | Oracle Updates (RSS) | 0 | 06-06-2008 07:10 PM |
| Oracle 10G best practices on Power6 AIX5.3 | JodyTek | AIX | 1 | 05-07-2008 07:41 AM |
| Korn Shell Best Practices | mtravis | Shell Programming and Scripting | 1 | 02-14-2008 03:11 PM |
| scripting guru's pls help me with scripting on AIX | thatiprashant | Shell Programming and Scripting | 1 | 01-20-2006 07:58 PM |
| User generated FAQ and Best Practices section | kduffin | Post Here to Contact Site Administrators and Moderators | 5 | 11-21-2003 09:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
Scripting Best Practices
Hi - I am new to this and was wondering if some of you can help me out. I am just starting to write scripts and need some guidelines on creating scripts. I'm calling them "Best Practices"...what should I do and not do when creating scripts.
All I know so far is that I should avoid putting usernames/passwords in scripts and I should avoid hard-coding a host name in a script. I would think there are a lot more of things like this, so if you could help me out, I would greatly appreciate it. Thanks! Todd |
|
||||
|
Quote:
http://www.tldp.org/LDP/abs/html/index.html HTH. |
|
|||||
|
When I first had the need to write scripts, this was the first place I looked. Here's some of the things I always do:
|
|
|||||
|
and ...
* keep the same form throughout for your code ... inconsistent coding styles make debugging a lot harder regardless of who's doing it ... look at the 3 "if" forms below that people use in ksh scripting --- they do the same things but debugging could be prolonged if you used all of them in the same script instead of just 1 as the patterns are different ... Code:
form 1:
if [ cond ]; then
command
fi
form 2:
if [ cond ]
then
command
fi
form 3:
[ cond ] && command
* try not to hardcode file and/or directory paths ... makes it easier to test if you could use this or that file instead of the production file or directory ... like indo says --- variables are your friends! * test as much as possible on a non-production server that closely mirrors the production environment ... unless you want to risk losing live production data --- that could be detrimental to your employment |
|
|||||
|
I think all of this leads to a few words that my prof in college taught me.
Modularity... Write code in modules/sections so that nothing is hard coded where possible and that sections of the code can be excluded/replaced/deleted and the program will still function with no other modification. Documentation.... If your programming out lives you, the next person will need to know what the heck you were doing. reading the code can be confusing, but comments help greatly. Use of echo... When troubleshooting your scripts insert echo commands in loops and wherever a decision is made in a forking statement like if/then/else or while/true or in case statements..... this aids in making sure to test all your logic down every path. |
| Sponsored Links | ||
|
|