- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: getopts command not working at expected
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 12:47 PM
08-18-2008 12:47 PM
getopts command not working at expected
I am writing a script using getopts, running in "sh" shell HP-UX 11.11. My optstring is like this
:gru:f:
However, during script tests, when invoked like this:
script -g -u -f
it places the string "-f" in OPTARG variable, instead of detecting the "u" option with missing argument and let OPTARG unset as the help describes it should do.
Of course I could add extra logic to catch this, but it would be better if the command performed as expected, unless there is something I am missing. Thank you for any comment yo have for me.
Jose Enrique Gonzalez
Caracas, Venezuela
- Tags:
- getopt/getopts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 12:53 PM
08-18-2008 12:53 PM
Re: getopts command not working at expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 01:08 PM
08-18-2008 01:08 PM
Re: getopts command not working at expected
> it places the string "-f" in OPTARG variable, instead of detecting the "u" option with missing argument
I think this is correct. All that this is checking is that something (an argument or a switch) follows '-u'. What follows the '-u' in this example is the '-f' string.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 01:35 PM
08-18-2008 01:35 PM
Re: getopts command not working at expected
So -u will get -f as a argument data.
getopts get the arguments sequencially
-guf will find -g with no arg, and -u with "f" as argument
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 02:02 PM
08-18-2008 02:02 PM
Re: getopts command not working at expected
Another way of looking at this is that 'getopts' helps you parse switches and arguments. While it "helps" it still requires "help" (i.e. some additional code).
Regards!
...JRF...