03-29-2019
Welcome to the forum.
Quote:
Originally Posted by
sharkura
... the only effect of adding ARGS... to my script causes the positional arguments to be ignored
Which is as specified.
Quote:
... nothing I've tried does anything with the optional arguments.
Strange - appending a "line" of options should (and DOES!) make
getopts evaluate those in lieu of the positional parameters, and it does for me. Pls (I know you dislike this) show an example of your failed attempts.
EDIT: Are you sure you did differentiate between the
bash builtin
getopts and the external command
getopt?
Last edited by RudiC; 03-29-2019 at 11:48 AM..
This User Gave Thanks to RudiC For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi, I use getopts in this way:while getopts ":d:f:crapv" Option
do
case $Option in
d ) BACKUP_DIR="$OPTARG";echo $BACKUP_DIR;; #echo fot test
c ) compress_file;;
r ) remove_file;;
a ) remove_file && compress_file;;... (2 Replies)
Discussion started by: mbarberis
2 Replies
2. Shell Programming and Scripting
Hi,
I'm using bash and ksh93 compatible derivatives.
In a recent getopts experience, I found myself spending far too much
time on this little problem. I hope someone can help...
So here's the deal.
I want to build have a command line interface that accepts either zero,
one, or... (4 Replies)
Discussion started by: duderonomy
4 Replies
3. Shell Programming and Scripting
Hi there, if i have a simple getopts like below ...how can i make it so that if somebody enters more than one -g argument for example, it will error with a " you cannot enter more than one -g" or something like that.?
I want to only allow one instance of a -g or a -h etc ..
while getopts... (1 Reply)
Discussion started by: hcclnoodles
1 Replies
4. Programming
Is it possible to have a non-const reference variable as an OPTIONAL/DEFAULT parameter to c++ function
ex
void read(string &data,int &type=0 /*or something*/) ;
so i will call
read(data);
//or
int type;
read(data,type);
printf("Type =%d",type);
I found one dirty workaround
... (2 Replies)
Discussion started by: johnbach
2 Replies
5. Shell Programming and Scripting
Hi Gurus
I am trying to figure out (with not much success) how to pass two values to a single getopts argument ... for example
./script -a Tuesday sausagesThe $OPTARG variable seems to only get populated with the first argument. What im looking to do is to process the first argument (i.e.make... (6 Replies)
Discussion started by: rethink
6 Replies
6. Shell Programming and Scripting
In the below code
while getopts :rfw:d:s:a: options
do
case "$options" in
r) echo reverse;;
f) echo forward;;
w) window=$OPTARG;;
d) duration=$OPTARG;;
s) search=$OPTARG;;
a) value=$OPTARG;;
*) help; exit;;
esac
done
... (2 Replies)
Discussion started by: Amutha
2 Replies
7. Shell Programming and Scripting
I'm using getopts to process command line args in a Bash script. The code looks like this:
while getopts ":cfmvhs:t:" option; do
case $option in
c) operationMode="CHECK"
;;
f) operationMode="FAST"
;;
m) ... (6 Replies)
Discussion started by: gencon
6 Replies
8. Shell Programming and Scripting
Hi,
I want to capture space as well from the argument
eg:
script.ksh -m "Message from xyz" -e "email@xyz.com"
script.ksh -m 'Message from xyz' -e 'email@xyz.com'
I am parsing using getopts, but for option "m" OPTARG is returning only "Message".
Please use code tags next time for... (9 Replies)
Discussion started by: tostay2003
9 Replies
9. 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
10. Shell Programming and Scripting
Hi Unix Gurus,
i am on learning path of unix, and yet to discover many things. I came across with this requirement where i need to pass parameters but the position of parameters is not fixed so after doing some google search got to know "getopts" can handle that. So here is my code:
function... (3 Replies)
Discussion started by: gnnsprapa
3 Replies