Updated today, gotten better… redone.
getopt is a command used in scripts to parse their options and add a basic error checking ability.
getopt is not
getopts the bash built-in that has similiar functionality. Urban Vagabond explains:
getoptsare different beasts, and people seem to have a bit of misunderstanding of what they do.
getoptsis a built-in command to bash [that] processes command-line options in a loop and assigns each found option and value in turn to built-in variables [(so that they can be further processed)].
getopt, however, is an external utility program, and it doesn’t actually process your options for you the way that [(e.g.)] bash getopts, the Perl Getopt module, or the Python optparse/argparse modules do. All that
getoptdoes is canonicalize the options that are passed in — (i.e. convert them to a more standard form) so that it’s easier for a shell script to process them.
For example, a use of getopt converts the following:
tmpscript -abd -ooutfile.txt
tmpscript -a -b -d -o outfile.txt
getopt can also process the long format option of
--output=/tmp.... Also basic error check abilities, it has:
tmpscript -c tmpscript: invalid option -- 'c'
tmpscript -o tmpscript: option requires and argument -- 'o'
getopt gets defined by telling it the available options in short and long form (if you like). An option with a colon (:) following denotes that an argument is required for that option. If followed by two colons the argument is optional. Here is an example:
Options are generally set as variables so that they can defined how to be used after the while loop (usually, so that mainly they are processed in the right order).
getopt parses in the same order as specified on the input, so a
-a -d -b input would not work real well if the
-d option required the
-b option to run correctly.
One caveat of
getopt is that each option allows either one or no arguments to follow. So in input like
tmpscript -v --files file1.txt file2.txt file3.txt just isn’t possible in any type of predictable-fashion. One can however use quotes on the input:
tmpscript -v --files "file1.txt file2.txt"
or use mutiple options (
-f file1.txt -f file2.txt) and append them to an array, as seen, here.
I decided to get the LS IPS224V-PN and here is a look at it. First thing I noticed was that the stand was a bit… rickety, probably from the thin neck. This does get noticed especially with the desktop I own, tetters. The second thing I noticed was how even the picture was: good, crisp, even, vibrant. The other thing I noticed was the permeating, yellow din that I’m familiar with with LEDs. This last thing can fortunately be adjusted).
|Input||D-Sub, DVI, HDMI|
I’m not sure what ips is but I think it contributes to the nice viewing angle.
Setup was real easy, took no more than a few minutes and monitor calibration was basic.
The color temperature of cool does a good job to neutralize the yellow color the LED; however the custom setting did better with pictures.
Alternate (yellow LED color remains):
Ultimately I choose to use the cool temperature.
The power button is a large half-circle with an refracting light to indicate power-saving. However, it is extremely bright. There is an option to turn it off when the power is off, but it will still be seen in standby-mode; I’ve had to cover mine up.
I got this display for reading and it is good for that. Text looks very nice. But it also is good with pictures at least as far as my semi-professional eye is concerned. The 14ms (WTG?) response time is a bit on the high end. Videos do show a bit of “ghosting” but it doesn’t bother me that bad.
When I’m about to edit a configuration file or a bash script, sometimes I don’t know if the edit will work. In these cases I create a backup of it in numbered order (to keep track of them if I need to revert the changes). Because this is something I regularly do, I decided to build a script to make this easy. The usage is basic: define the file and destination-directory:
# bckfile definedfile.bash . ‘/home/johndoe/.local/bin/definedfile.bash’ -> ‘/home/johndoe/.local/bin/definedfile_00.bash’
Optionally a tag can be added too:
bckfile youdle .vault/ new ‘/home/johndoe/.local/bin/youdle’ -> ‘/home/johndoe/.local/bin/youdle_02-new’
A limitation of the script is that filename cannot have ‘periods’ in their filename. A heuristics of discovering multiple extensions and with . in the filename itself would be tough.
I am really lazy with my editors. I have aliases in my shell configuration for gedit and vim that are very basic:
alias v="vim -p" # open in tab alias sv="sudo vim -p" alias g="bgcmd gedit" alias sg="bgcmd gksudo gedit"
This is very nice for me because I use my editors quite a bit. One thing I needed though was a command that would create and open a temporary file in gedit. The main reason for this is that at the time I don’t know how to name or place the file properly. Another reason is that at other times I like to have a scratchpad but would lose information if it was just a New File and a crash… happened.
gt will create and open a file named of the current time (MMDDhhmm) and will be saved in the trash folder. If
gt is followed by a name (e.g.
gt cssbox or
cssbox.css) the name will be appended to the current time.
The name is helpful if wanting to dig the file out of the trash folder at a later time.
Because it was the authors first effort to write a man page, talk was that it was good to use Pod2Man. Pod2man is an application that converts text using Plain Old Document (POD) formatting to traditional manual (man) pages. POD markup is easy to do and
pod2man is conveniently pre-installed on most Linux distributions (as it is part of the Perl package).
To get a good idea of what to do, here is a basic example demonstrating the formatting (of a fictitious program
=encoding UTF8 =head1 NAME dr-smile - output platitudes to help to improve one's mood =head1 SYNOPSIS dr-smile [B<--happy>] [B<--joke>=F<type>] =head1 DESCRIPTION B<dr-smile> outputs jokes and happy thoughts designed to make one fell F<--better>. It has the ability to output pleasant thoughts, jokes, good memories, optimistic fortunes... B<dr-smile> I<isn't> a replacement for a professional doctor, please use responsibly and enjoy. Additional options are available in the configuration file F</etc/dr-smile.conf>. =over 4 =item B<-h>, B<--happy> A general happy thought will be output (e.g. C<dr-smile --happy>). =item B<-j> F<type>, B<--joke>=F<type> A good-sense joke will be told. The types are: F<knock> and F<oddball>. Read more in B<jokes(1)>. =back
There is both text formatting and section formatting that is required for a man page.
All the POD text formatting tags needed to know are as follows:
Man pages use two types of formatting (that I’ve ever seen). That are implemented by POD’s bold formatting and PODS filename-or-italic formatting:
|Formatting type||Used for|
|POD Bold formatting||
|POD Filename formatting
POD Italic formatting
There are three section tags that are used in
pod2man (that I know of). The
pod2man manual refers to these as Command Paragraphs and they are: header/category sections, item sub-sections, and “over” sub-sub-sections for additional descriptions of item sections. References to all of these are in the above example.
- Header/Category sections are the block descriptors and their contents (like NAME, and DESCRIPTION…).
- Item sections refer to options generally and often override
=oversections for their list item.
- Over sections refer to option descriptions.
General layout structure
Man pages follow a basic (though liberal) structure can be well represented by this:
NAME The name of the command, followed by a one-line description of what it does. SYNOPSIS A representative invocation of how to run the command and options it has. DESCRIPTION A detailed description of the functioning of the command. OPTIONS A list of it's options (these are sometimes put in DESCRIPTION). EXAMPLES Some examples of common usage. BUGS List known bugs. SEE ALSO A list of referenced or related commands. AUTHOR Specifying the contact information. COPYRIGHT Specifying the copyright information.
The order of categories varies a bit from man page to man page. The first four categories are almost always the same, however the remaining vary a bit. The above layout is an mnemonic aggregate of category order of the man pages that the author has seen.
Convert pod format to manual page
Pod2man usage is basic:
pod2man dr-smile.pod > dr-smile.1
However, these additional options will probably be wanted to be added, plus compression:
pod2man --section=1 --center="dr-smile manual" --name="dr-smile" --release="1.0" dr-smile.pod | gzip > dr-smile.1.gz
xuserrun is a bash script to run a command on the active X.org server display. This is primarily necessary if from within another environment (different user, console, cron, boot script…). xuserrun gathers DISPLAY and user environmental variables via systemd and passes them on to be able to dothis. xuserrun is designed for use with only a single user X.org server display. Running it is basic:
xuserrun xclock -digital
Tto put out a notification:
xuserrun notify-send "Hello, Dave."