07-25-2008
getopts with non-option arguments?
Hello everyone,
Is it possible to use getopts and also receive arguments without option flags?
e.g. myscript arg1 arg2 -a arg3 -b arg4
If so, how do you stop getopts from exiting as soon as it detects the non-option arguments?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all,
I am parsing command line options using getopts.
The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument.
Below is the script:
while getopts :hd:t:s:l:p:f: opt
do
case "$opt" in
-h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies
2. Shell Programming and Scripting
Hi,
I have a script that ran perfectly on Solaris 5.8
However after upgrade to Solaris 5.10 it started failing.
I invoke the script as below:
./TestScript3.ksh --dir $APP_DATA_IN_OLD $NDM_DATA/$NEXT_FILE
When i execute it i get the following error "getopts: dir bad option(s)".
Please let... (1 Reply)
Discussion started by: JoeJoseph
1 Replies
3. Shell Programming and Scripting
Hello,
Does getopts have some way of handling the use of an option that requires a parameter more than once on the command line.
e.g. mycmd -a john -a jane
I came up with a solution using arrays (shown below), but wonder if getopts has some other way of handling it. Other solutions... (2 Replies)
Discussion started by: CarlosNC
2 Replies
4. UNIX for Dummies Questions & Answers
Hi, I'm having problems with a script where I wanted every single option specified in the command line to have an argument taken with it, but for some reason only d works in the code I will be showing below.
For example if I did ./thisfile -a something
it would come up with "a chosen with " as... (2 Replies)
Discussion started by: IceX
2 Replies
5. Shell Programming and Scripting
I have a script with several options and during testing I found that the \? option does not handle options without dashes as I would expect. Then I run the script with any option that does not include a dash, it runs the script when I would expect \? to catch it and error.
I've tried this with... (2 Replies)
Discussion started by: HexKnot
2 Replies
6. Shell Programming and Scripting
Hi all,
I am trying to use long arguments for my existing script. right now my script would work if given <script_name> -t <arg1> -b <arg2> -v <arg3>. The script code is shown below.
while getopts t:v:b: OPT;do
case "$OPT" in
t) Todo=$OPTARG;;
b) Batch=$OPTARG;;
... (3 Replies)
Discussion started by: SSSB
3 Replies
7. Shell Programming and Scripting
hi, here is a ksh script i wrote using getopts...
i want to find out how i can run it in default mode when no option is mentioned and no arguments are provided... ?
i.e if the script name is final1, then just running final1 should run in default mode....
while getopts 1:2:3:4: mode ... (1 Reply)
Discussion started by: pravsripad
1 Replies
8. Shell Programming and Scripting
Is it possible to get a script that uses getopts to accept options and arguments in any order?
eg. -g -h 2 4 works like -g 2 -h 4. (1 Reply)
Discussion started by: lee.n.doan
1 Replies
9. Shell Programming and Scripting
Hello,
I am using below code in AIX env to interpret -n option given in argument while executing the script .I want to give another argument -t
#!/bin/sh
#set -x
while getopts ":n:" opt; do
case "$opt" in
n)
host=$OPTARG
shift 2
;;
*)... (3 Replies)
Discussion started by: Vishal_dba
3 Replies
10. Shell Programming and Scripting
Hello everyone,
I need help in understanding the default value for getopts option's argument in ksh. I've written a short test script:
#!/bin/ksh
usage(){
printf "Usage: -v and -m are mandatory\n\n"
}
while getopts ":v#m:" opt; do
case $opt in
v) version="$OPTARG";;
... (1 Reply)
Discussion started by: da1
1 Replies
LEARN ABOUT DEBIAN
shevek_istring
shevek::istring(3) Library Functions Manual shevek::istring(3)
NAME
shevek::istring -
shevek::istring is a C++ version of scanf.
SYNOPSIS
#include <iostring.hh>
Public Member Functions
istring ()
Create a new istring with no data.
istring (Glib::ustring const &str)
Create a new istring with data.
void init (Glib::ustring const &str)
Set new data to an existing istring.
void push ()
Push the current position to the stack so it can be restored later.
int pop (bool keep=false)
Pop the last pushed position from the stack.
void reset ()
Set the current position to 0, but don't change the stack.
Glib::ustring rest () const
Get remaining string.
void skip (Glib::ustring::size_type p)
Skip some characters.
bool operator() (Glib::ustring const &format)
Read a constant string from the input.
template<typename T1 > bool operator() (Glib::ustring const &format, T1 &arg1)
Read a string containing one argument from the input.
template<typename T1 , typename T2 > bool operator() (Glib::ustring const &format, T1 &arg1, T2 &arg2)
Read a string containing two arguments from the input.
template<typename T1 , typename T2 , typename T3 > bool operator() (Glib::ustring const &format, T1 &arg1, T2 &arg2, T3 &arg3)
Read a string containing three arguments from the input.
template<typename T1 , typename T2 , typename T3 , typename T4 > bool operator() (Glib::ustring const &format, T1 &arg1, T2 &arg2, T3
&arg3, T4 &arg4)
Read a string containing four arguments from the input.
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 > bool operator() (Glib::ustring const &format, T1 &arg1, T2
&arg2, T3 &arg3, T4 &arg4, T5 &arg5)
Read a string containing five arguments from the input.
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 > bool operator() (Glib::ustring const &format,
T1 &arg1, T2 &arg2, T3 &arg3, T4 &arg4, T5 &arg5, T6 &arg6)
Read a string containing six arguments from the input.
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 > bool operator() (Glib::ustring
const &format, T1 &arg1, T2 &arg2, T3 &arg3, T4 &arg4, T5 &arg5, T6 &arg6, T7 &arg7)
Read a string containing seven arguments from the input.
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 > bool operator()
(Glib::ustring const &format, T1 &arg1, T2 &arg2, T3 &arg3, T4 &arg4, T5 &arg5, T6 &arg6, T7 &arg7, T8 &arg8)
Read a string containing eight arguments from the input.
Static Public Member Functions
template<typename T > static T direct (Glib::ustring const &data, Glib::ustring const &format, T def=T())
Read a variable from given data and return it.
Detailed Description
shevek::istring is a C++ version of scanf.
It uses templates to allow expanding it to user-defined types, but it still uses a format string to make it better translatable.
Member Function Documentation
template<typename T > static T shevek::istring::direct (Glib::ustring const &data, Glib::ustring const &format, Tdef = T ()) [inline, static]
Read a variable from given data and return it. This allows using a shevek::istring in an expression without the need to create a new
variable for it. If the input doesn't match the format, def is returned.
int shevek::istring::pop (boolkeep = false)
Pop the last pushed position from the stack. If keep is true or not given, the current position is restored to the last position. If it is
false, the current position is not changed.
Author
Generated automatically by Doxygen for libshevek from the source code.
libshevek Fri May 11 2012 shevek::istring(3)