Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally, I have a few conventions I like to stick to for every script I write. I write all scripts with assumption that other people might read them. </p> <p>I start every script with my header, </p> <pre><code>#!/bin/bash # [ID LINE] ## ## FILE: [Filename] ## ## DESCRIPTION: [Description] ## ## AUTHOR: [Author] ## ## DATE: [XX_XX_XXXX.XX_XX_XX] ## ## VERSION: [Version] ## ## USAGE: [Usage] ## </code></pre> <p>I use that date format, for easier grep/searching. I use the '[' braces to indicate text people need to enter themselves. if they occur outside a comment, I try to start them with '#['. That way if someone pastes them as is, it wont be mistaken for input or a test command. Check the usage section on a man page, to see this style as an example.</p> <p>When I want to comment out a line of code, I use a single '#'. When I am doing a comment as a note, I use a double '##'. The <code>/etc/nanorc</code> uses that convention also. I find it helpful, to differentiate a comment that was chosen not to execute; verses a comment that was created as a note.</p> <p>All my shell variables, I prefer to do in CAPS. I try to keep between 4 - 8 characters, unless otherwise necessary. The names relate, as best as possible, with their usage.</p> <p>I also always exit with 0 if successful, or a 1 for errors. If the script has many different types of errors (and would actually help someone, or could be used in some code in some way), I would choose a documented sequence over 1. In general, exit codes are not as strictly enforced in the *nix world. Unfortunately I have never found a good general number scheme. </p> <p>I like to process arguments in the standard manner. I always prefer getopts, to getopt. I never do some hack with 'read' commands and if statements. I also like to use the case statement, to avoid nested ifs. I use a translating script for long options, so --help means -h to getopts. I write all scripts in either bash (if acceptable) or generic sh.</p> <p>I NEVER use bash interpreted symbols (or any interpreted symbol) in filenames, or any name for that matter. specifically... " ' ` $ &amp; * # () {} [] -, I use _ for spaces.</p> <p>Remember, these are just conventions. Best practice, of coarse, but sometimes you are forced outside the lines. The most important is to be consistent across and within your projects.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload