添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
有腹肌的猕猴桃  ·  API: Projects·  5 小时前    · 
虚心的排球  ·  API: Time Entries·  5 小时前    · 
纯真的冲锋衣  ·  API: Statuses·  5 小时前    · 
聪明的红薯  ·  2023版:深度比较几种.NET ...·  6 小时前    · 
行走的豆芽  ·  SDL: joystick: get ...·  9 月前    · 
冷静的葫芦  ·  陈佩奇 – ...·  11 月前    · 
爽快的石榴  ·  python 文本转html-掘金·  1 年前    · 
script.ksh -m "Message from xyz" -e "[email protected]" script.ksh -m 'Message from xyz' -e '[email protected]'

I am parsing using getopts, but for option "m" OPTARG is returning only "Message".

Humm, I suspect something else is going on if quotes fail. getopts in ksh is a somewhat complex beast compared to other getopts. Which version of ksh are you using?
Any of the following should work:
Code :
script.ksh -m "string with white space"
script.ksh -m 'string with white space'
script.ksh -m string\ with\ white\ space
script.ksh -m string' with'\ "whi"te" "''space

script.ksh -m "string with white space" script.ksh -m 'string with white space' script.ksh -m string\ with\ white\ space script.ksh -m string' with'\ "whi"te" "''space

If you leave out the quotes around $OPTARG, it'll catch only the first word of a string.
Hope this helps

Here's a script I wrote a long time ago as I was having the same issues.
I'll modify it as necessary when I have getopts problems.
Code :
aflag=
bflag=
while getopts :ab:t: opt
  case $opt in
    a) aflag=1;;
    b) bflag=1
       bval="$OPTARG";;
    t) tflag=1
       tval="$OPTARG";;
    ?) printf "Usage: %s: [-a] [-b value] args\n" $0
       exit 2;;
if [ ! -z "$aflag" ]; then
  printf "Option -a specified\n"
if [ ! -z "$bflag" ]; then
  printf 'Option -b "%s" specified\n' "$bval"
if [ ! -z "$tflag" ]; then
  printf 'Option -t "%s" specified\n' "$tval"
shift $(($OPTIND - 1))
printf "Remaining arguments are: %s\n" "$*"

>getopts.sh -b "this is my opt" -t hello\ all
Option -b "this is my opt" specified
Option -t "hello all" specified
Remaining arguments are:

>getopts.sh -b "this is my opt" -t hello\ all Option -b "this is my opt" specified Option -t "hello all" specified Remaining arguments are:


I think I see the problem, but need a fix.
I am calling a shell script structured as below, though I am placing the arguments in quotes, looks quotes are getting lost through the $* being passed to the function. Can you please suggest a remedy.
Code :
parse_cmd () {
   getopts functionality
main () {
  parse_cmd $*
main $*

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...
Tagged: args, getopts, optional arguments
Discussion started by sharkura and has been viewed 3,776 times.
There has been 2 replies and 1 user thanks in this discussion.
The last reply was by drl .
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";;
Tagged: shell scripts
Discussion started by da1 and has been viewed 5,952 times.
There has been 1 reply in this discussion.
The last reply was by drl .
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...
Tagged: shell scripts, solved
Discussion started by pathunkathunk and has been viewed 10,517 times.
There has been 1 reply in this discussion.
The last reply was by tange .
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...
Tagged: empty, getops, set, shell scripts, solved
Discussion started by sea and has been viewed 13,678 times.
There has been 0 replies in this discussion.
The last reply was by sea .
h) echo $USAGE ; exit 0;; r) export REQ_ID="$OPTARG";; t) TIMESPAN="$OPTARG";; d) detail="true";; ) ...
Tagged: optarg, parameters, shell scripts
Discussion started by mohsin.quazi and has been viewed 3,864 times.
There has been 0 replies in this discussion.
The last reply was by mohsin.quazi .
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...
Tagged: shell scripts
Discussion started by rethink and has been viewed 15,962 times.
There has been 6 replies in this discussion.
The last reply was by jaysunn .
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...
Tagged: shell scripts
Discussion started by hcclnoodles and has been viewed 7,280 times.
There has been 1 reply in this discussion.
The last reply was by drl .
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...
Tagged: getopts, list, shell scripts
Discussion started by duderonomy and has been viewed 18,293 times.
There has been 4 replies in this discussion.
The last reply was by unSpawn .
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 case "$opt" in -h|-\?)...
Tagged: argument, getopts, shell scripts
Discussion started by gurukottur and has been viewed 16,467 times.
There has been 2 replies in this discussion.
The last reply was by era .
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,...
Tagged: shell scripts
Discussion started by convenientstore and has been viewed 7,291 times.
There has been 7 replies in this discussion.
The last reply was by jgt .