Getopts - space in argument (OPTARG)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getopts - space in argument (OPTARG)
# 8  
Old 05-08-2014
Put quotes around $*
# 9  
Old 05-08-2014
If that doesn't work, try "$@" instead, quotes and all. It's special; it passes arguments literally as they came, without splitting and yet still split as they were (despite the quotes).
# 10  
Old 05-08-2014
Yes, double-quoted @ is probably what you want. Also, OP, next time post working code in your first post. It would have saved our volunteers a day's worth of guesses. Even though pseudo-code may shed some light, there is no subsitute for actual code (perhaps a minimized version of your actual script) which demonstrates the problem.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Question about getopts optional argument [args...]

There are many places where I can see the syntax description for optargs, which, usually boils down to this: getopts OPTSTRING VARNAME where: OPTSTRING tells getopts which options to expect and where to expect arguments VARNAME tells getopts which shell-variable to use for option reporting... (2 Replies)
Discussion started by: sharkura
2 Replies

2. Shell Programming and Scripting

ksh - default value for getopts option's argument

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

3. Shell Programming and Scripting

Xargs error: insufficient space for argument

I'm trying to crudely hack my way through some data processing. I have file.txt with around 17,000 lines like this: ACYPI002690-PA.aa.afa.afa.trim_phyml_tree_fullnames_fullhomolog.txt 3 72 71 ACYPI002690-PA.aa.afa.afa.trim_phyml_tree_fullnames_fullhomolog.txt 97 111 71... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

4. Shell Programming and Scripting

[BASH] getopts, OPTARG is passed but empty

EDIT: -- SOLVED -- Heyas, Getting used to optargs, but by far not understanding it. So i have that script that shall be 'changeable', trying to use the passed arguments to modify the script visuals. Passing: browser -t test -d sect $HOME Where -t should change the title, and -d... (0 Replies)
Discussion started by: sea
0 Replies

5. Shell Programming and Scripting

OPTARG is not taking SPACE

Hi I have below code in one of my shell script: if ; then fail $USAGE; fi while getopts hz:r:t:dz: o do case "$o" in h) echo $USAGE ; exit 0;; r) export REQ_ID="$OPTARG";; t) TIMESPAN="$OPTARG";; d) detail="true";; ) ... (0 Replies)
Discussion started by: mohsin.quazi
0 Replies

6. Shell Programming and Scripting

getopts : two values to a single argument ?

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

7. Shell Programming and Scripting

getopts ... only allow a single instance of an argument?

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

8. Shell Programming and Scripting

getopts and a list argument

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

9. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

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

10. Shell Programming and Scripting

replacing single space in argument

I want to write a script which will check the arguments and if there is a single space(if 2 more more space in a row , then do not touch), replace it with _ and then gather the argument so, program will be ran ./programname hi hello hi usa now hello hello so, inside of program,... (7 Replies)
Discussion started by: convenientstore
7 Replies
Login or Register to Ask a Question