There are many schemes / methods / alternatives to help process command line -- CLI -- options. Here are a few. Some take a bit of effort to learn, but they will be time-savers in future work.
I especially like the ones that create man-like pages, and help displays automatically ... cheers, drl
I'm just not sure where to start looking into this. I want to be able to create switches for my script. Back in the day I'd make my scripts interactive...you know:
echo "what report do you want"
echo "A)boxes with errors"
echo "B)boxes with more than 5 errors"
echo "C)Service groups that have... (3 Replies)
I have wasted one working day writing this scripts.
It compares two folders and make a good tabbed report about their differences.
#!/bin/bash
function DRAW_DEPTH () {
ROUND=$1
while
do
printf %s " "
ROUND=`expr $ROUND - 1`
done
printf %s "|- "
}
function MAIN () {... (9 Replies)
I'm trying to write a bash script and call it "compile" such that running it allows me to compile multiple files with the options "-help," "-backup," and "-clean". I've got the code for the options written, i just can't figure out how to read the input string and then translate that into option... (5 Replies)
I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing
set
you can also use them "on the command line when running a script..." and it lists this in a small table:
set -o option Command Line... (5 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Creating bash script the dd command and its new options (-l -U)
-l options to lowercase contents of file
-U... (2 Replies)
what i want to be is that i would like to reinvent new options that have the same functionality as
...
-u is the same functionality of conv=ucase
and -l have the same functionality as conv=lcase...
is there a way that i can put these in my script so that
whenever i will typed in command... (12 Replies)
I have the following code and I am calling it using
./raytrac.bash -u
and getting problems. For some reason opt_usage is still 0.
opt_usage=0
iarg=0
narg=$#
while (($iarg < $narg))
do
(( iarg = $iarg + 1 ))
arg=$argv
usrInputFlag=`echo $arg | awk '/=/ {print 1}; ! /=/... (22 Replies)
hi guys
we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
I'm trying to run a script that will remotely copy another script to remote host and run copied script to remote server with automatic options-
#! /bin/bash
HOSTNAME="1 2"
for HOST in $HOSTNAME;
do
scp diskFrag.sh login@$HOST:/home/login
sleep 30
ssh login@$HOST... (2 Replies)
Discussion started by: Mannu2525
2 Replies
LEARN ABOUT X11R4
getopt_long
GETOPTS(3) libbash getopts Library Manual GETOPTS(3)NAME
getopts -- libbash library for command line parameters parsing
SYNOPSIS
$retval getopt_long <Instructions> <Parameters>
DESCRIPTION
This is a documentation for libbash getopts library, that implements getopt_long function for bash(1). For documentation of bash getopts
function, please see getopts(1) ( getopts(1posix) on some systems).
Here is a table for reference:
getopts(1) (or 1posix on some systems) implemented by bash
getopts(3) implemented by libbash.
getopt(1) implemented by getopt utils (part of util-linux)
getopt_long(1) implemented by libbash and installed to section 1 instead of 3 to prevent collision with C man pages.
getopt(3) implemented by GNU C library.
getopt_long(3) implemented by GNU C library.
I have also seen separate getopt utility which part of util-linux package.
The getopt_long function parses the command line arguments. It uses Instructions as the rules for parsing the Parameters.
The Instructions
A string that specifies rules for parameters parsing. The instructions string is built of a group of independent instructions, separated by
a white space. Each instruction must have the following structure:
-<SingleLetter>|--<MultiLetter>-><VariableName>[:]
This structure contains three parts:
-<SingleLetter>
This is the parameter single-letter sign. For example -h.
--<MultiLetter>
This is the parameter's corresponding multi-letter sign. For example --help.
<VariableName>[:]
This is the name of the variable that will contain the parameter value. For example: HELP.
The Variable name can represent one of two variables types:
Flag variable (not followed by ':')
In this case, it will hold the value 1 if 'on' (i.e. was specified on command line) and will not be defined if 'off'.
Value variable (followed by ':')
In this case, the value it will hold is the string that was given as the next parameter in the Parameters string (Separated by
white-space or '=' ). If input contains more then one instance of the considered command line option, an array of the given
parameters will be set as the value of the variable.
The Parameters
The Parameters are simply the parameters you wish to parse.
RETURN VALUE
This function returns a string that contains a set of variables definitions. In order to define the variables, this string should be given
as a parameter to eval function. This value is returned in the variable $retval.
EXAMPLES
Parse command line parameters looking for the flags -h | --help and -v | --version and for the value -p | --path :
getopt_long '-h|--help->HELP
-v|--version->VERSION
-p|--path->PATH:' $*
eval $retval
In this example, for the parameters --help --path=/usr/ the variables that will be created are:
HELP=1
PATH=/usr/
for the parameters --help --path=/usr --path=/bin the variables that will be created are:
HELP=1
PATH=(/usr /bin)
BUGS
Values must not contain the string `__getopts__'. This string will be parsed as a single white-space.
A value should not start with an already defined multi-letter sign. If such a value exists, it will be treated as the equivalent singe-letter
sign. This bug only accures when using a single-letter sign, or a multi-letter sign that are not followed by a `='.
For example: If we have a script named `foo', and we parse the parameters `-d|--dir:' and `-f|--file:', then
foo -d --file
and
foo --dir --file
will not work
foo --dir=--file
will work.
AUTHORS
Hai Zaar <haizaar@haizaar.com>
Gil Ran <gil@ran4.net>
SEE ALSO ldbash(1), getopt_long(1), getopts(1), getopt(1), libbash(1), getopt(3), getopt_long(3)Linux Epoch Linux