LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > Subjectively
User Name
Password

Notices


This blog points to articles written on http://kirk.webfinish.com. These articles are mainly about shell scripting, PHP, and postgresql on Ubuntu and OS/X.
Rating: 3 votes, 3.00 average.

bash shell script to use getopts with gnu style long positional parameters

Posted 11-03-2009 at 05:04 PM by roybal

Here's a script that will accept --gnu-style-long-parameters and interpret them appropriately.

http://kirk.webfinish.com/2009/10/ba...al-parameters/
Posted in Uncategorized
Views 4045 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    Coincidentally, I've just gone through this very exercise. Your approach is an interesting alternative to mine, and I'll bear it mind for the future.

    FYI, my approach in this case was to simply use all short options for the script itself, and then convert them to the long options in the case statement. It wouldn't work for something with a large set of options, too messy.

    For example, the application takes a long option of --file filename, I use -f in the script:
    Code:
    case $opts in
      f)
         file="--file $OPTARG"
         ;;
    esac
    
    # call the app
    app "$file"
    A quick question, you, and the examples in the docs, use "eval set -- $args". I can't figure out the reason for the eval. Couldn't you simply use "set -- $args" to put the params into $1, $2, etc.

    Cheers,
    Nick
    Posted 11-04-2009 at 06:13 AM by padeen padeen is offline
  2. Old Comment
    Quote:
    Originally Posted by padeen View Comment
    A quick question, you, and the examples in the docs, use "eval set -- $args". I can't figure out the reason for the eval. Couldn't you simply use "set -- $args" to put the params into $1, $2, etc.

    Cheers,
    Nick
    The eval is there because parameters (like long file names with spaces) will get expanded to multiple parameters. I can add quotes around the parameters to "group" them again, but I need the eval to get 'set' to accept the quoted arguments.

    /bithead
    Posted 11-17-2009 at 12:46 PM by roybal roybal is offline
 

  



All times are GMT -5. The time now is 05:47 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration