How to parse long and/or short options in shell scripts
Hi ,
it has been a while since I have tried to parse command line arguments
made of both short and long options. There are many ways to do so but
not as many of them handle switch clustering in a flawlessly way. Here
is a snippet of code that illustrates my point. It is, however, far from
being straightforward (getopts is) since it requires to do the parsing
by hand. At last, the sample uses builtins commands only so the parsing
is expected to be optimal.
At parsing time, OPTARG holds the last expected option argument.
Last edited by Lie Algebra; 03-02-2009 at 01:46 AM..
I have a script which take 3 input parameters
1st - a date (i.e. current date)
2nd - type (i.e. A)
3rd - limit (i.e. 40)
normally the date parameter would be current date, so I thought I could do this
calculate.sh $(date +%Y-%m-%d) A 40
however, it seems like it can't be done,... (3 Replies)
Hi i am a newbie who is trying to input parameters into this script, but not sure where to start.
The parameters that need to be input are the baseline label "abc.0111.BL " mantioned bellow, and database string "abc/abcp@db2 @counter.sql "
Environment: Windows XP
Running script: Cygwin 3.2
... (2 Replies)
I have to write a script to verify input parameters;
say esr should be YES or NO other wise the script should print an error.
This is what i tried in my script but I get the following error
:
esr="YES"
if ; then
print " Error should specify esr options YES/NO"
else
esr =$esr
fi
... (2 Replies)
Hi!
I have a bunch of HTML files, which I want to parse to CSV files. Every page has a table in it, and I need to parse each row into a csv record.
With awk and sed, I managed to put every table row in separate lines. So my file looks like this:
<TR> .... </TR>
<TR> .... </TR>
...One... (1 Reply)
Hi, this is my problem
I have script with two parameters -n name and -s surname. Both have arguments and I want to know how parse these parameters with getopts. When you write
./names -n John -s White
it find you all persons, which name is John White, but when you write
./names -n John ... (1 Reply)
Hello,
I have this shell script that runs awk code by passing in parameters however now it doesn't work anymore with the parameters and I don't know why.
It removes duplicates from an input file based on a part of the last field and a key column. It removes the record with the older datetime... (0 Replies)
Hi!
Thank you ina advance for your Help. Sorry my english, Im from Argentina!
Great Place!!!
So, here si my problem
I have a variable, lets say PARAMETERS that could be set like this:
PARAMETROS="-Usistemas string1 -Astring2 -G -Y -Kcoco -Y string4 -Z"
or
PARAMETROS="string1... (1 Reply)
Hi,
I have a query regarding execution of a sql query having long listing of parameters ..I need to execute this query inside a shell script.
The scenario is like....
Suppose I have a file abc.txt that has the card numbers..it could be in thousands..
then I need to fire a query like
... (12 Replies)
Hi,
Is there a simple way to take input of parameters after the first one? As following example, if I assign others=$2, it only takes the second one, if I assign others=$@, it will include the first one. I may try to assign others="$2 $3 $4 $5 $6 $7 $8 $9", it looks very ugly and could missing... (1 Reply)
friends
and I can validate whether to run the shell has input parameters m event date, I occasionally happen something like this does not work
if $ 1 is null then
echo has entered input parameters
else
echo "parameter ok"
fi (2 Replies)
Discussion started by: tricampeon81
2 Replies
LEARN ABOUT SUSE
loggerutils
logger::utils(n) Object Oriented logging facility logger::utils(n)
__________________________________________________________________________________________________________________________________________________NAME
logger::utils - Utilities for logger
SYNOPSIS
package require Tcl 8.4
package require logger::utils ?1.3?
::logger::utils::createFormatCmd formatString
::logger::utils::createLogProc -procName procName ?options...?
::logger::utils::applyAppender -appender appenderType ?options...?
::logger::utils::autoApplyAppender command command-string log op args...
_________________________________________________________________DESCRIPTION
This package adds template based appenders.
::logger::utils::createFormatCmd formatString
This command translates formatString into an expandable command string. The following strings are the known substitutions (from
log4perl) allowed to occur in the formatString:
%c Category of the logging event
%C Fully qualified name of logging event
%d Current date in yyyy/MM/dd hh:mm:ss
%H Hostname
%m Message to be logged
%M Method where logging event was issued
%p Priority of logging event
%P Pid of current process
::logger::utils::createLogProc -procName procName ?options...?
This command ...
-procName procName
The name of the procedure to create.
-conversionPattern pattern
See ::logger::utils::createFormatCmd for the substitutions allowed in the pattern.
-category category
The category (service).
-priority priority
The priority (level).
-outputChannel channel
channel to output on (default stdout)
::logger::utils::applyAppender -appender appenderType ?options...?
This command will create an appender for the specified logger services. If no service is specified then the appender will be added
as the default appender for the specified levels. If no levels are specified, then all levels are assumed.
-service loggerservices
-serviceCmd loggerserviceCmds
Name of the logger instance to modify. -serviceCmd takes as input the return of logger::init.
-appender appenderType
Type of the appender to use. One of console, colorConsole.
-conversionPattern pattern
See ::logger::utils::createFormatCmd for the format of the pattern. If this option is not provided the default pattern
[%d] [%c] [%M] [%p] %m
is used.
-levels levelList
The list of levels to apply this appender to. If not specified all levels are assumed.
Example of usage:
% set log [logger::init testLog]
::logger::tree::testLog
% logger::utils::applyAppender -appender console -serviceCmd $log
% ${log}::error "this is an error"
[2005/08/22 10:14:13] [testLog] [global] [error] this is an error
::logger::utils::autoApplyAppender command command-string log op args...
This command is designed to be added via trace leave to calls of logger::init. It will look at preconfigured state (via ::log-
ger::utils::applyAppender) to autocreate appenders for newly created logger instances. It will return its argument log.
Example of usage:
logger::utils::applyAppender -appender console
set log [logger::init applyAppender-3]
${log}::error "this is an error"
BUGS, IDEAS, FEEDBACK
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category logger
of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for
either package and/or documentation.
KEYWORDS
appender, logger
COPYRIGHT
Copyright (c) 2005 Aamer Akhter <aakhter@cisco.com>
log 1.3 logger::utils(n)