Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse long option on Mac OSX Snow Leopard with standard getopt #13

Open
GoogleCodeExporter opened this issue Jun 26, 2015 · 10 comments

Comments

@GoogleCodeExporter
Copy link

$ ./hello_world.sh --help
flags:WARN getopt: illegal option -- -
getopt: illegal option -- e
getopt: illegal option -- l
getopt: illegal option -- p
 -h --
flags:FATAL unable to parse provided options with getopt.

---

$ ./hello_world.sh --name Bob
flags:WARN getopt: illegal option -- -
 -n ame -- Bob
flags:FATAL unable to parse provided options with getopt.

---

$ which getopt
/usr/bin/getopt

Original issue reported on code.google.com by gregory....@gmail.com on 29 Jul 2010 at 1:51

@GoogleCodeExporter
Copy link
Author

Fixed in CL# 146.

Original comment by kate.war...@gtempaccount.com on 28 Jun 2011 at 1:31

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Hi, has the fix been tested on Mac OS X?

When I try the example as given on the Wiki, I still get this reported error on 
Mac OS X 10.6.8


GoetheMBP-2:~ andreas$ head shflags
# $Id: shflags 147 2011-06-28 13:29:40Z kate.ward@forestent.com $
# vim:et:ft=sh:sts=2:sw=2
#
# Copyright 2008 Kate Ward. All Rights Reserved.
# Released under the LGPL (GNU Lesser General Public License)
#
# shFlags -- Advanced command-line flag library for Unix shell scripts.
# http://code.google.com/p/shflags/
#
# Author: kate.ward@forestent.com (Kate Ward)
GoetheMBP-2:~ andreas$ 
GoetheMBP-2:~ andreas$ 
GoetheMBP-2:~ andreas$ 
GoetheMBP-2:~ andreas$ cat test.sh
#! /bin/sh

source ./shflags

DEFINE_string name 'world' "somebody's name" n

FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"

echo $FLAGS_name
exit 0
GoetheMBP-2:~ andreas$ 
GoetheMBP-2:~ andreas$ 
GoetheMBP-2:~ andreas$ ./test.sh -n Kate
Kate
GoetheMBP-2:~ andreas$ ./test.sh --name Andreas
flags:WARN getopt: illegal option -- -
 -n ame -- Andreas
flags:FATAL unable to parse provided options with getopt.
GoetheMBP-2:~ andreas$ which getopt
/usr/bin/getopt

Original comment by andreas....@gmail.com on 15 Aug 2011 at 6:42

@GoogleCodeExporter
Copy link
Author

Apparently, my getopt version is not the enhanced one. This seems not to be 
recognized by the test in the beginning of shflags (line 136 of CL# 174).

GoetheMBP-2:~ andreas$ echo "\"`getopt --version`\""
" --"

Instead of "-- " as tested for by shflags.


GoetheMBP-2:~ andreas$ if [ "`getopt --version`" = '-- ' ]; then echo "Standard 
getopt"; fi
GoetheMBP-2:~ andreas$ if [ "`getopt --version`" = ' --' ]; then echo "Standard 
getopt"; fi
Standard getopt
GoetheMBP-2:~ andreas$ 

Original comment by andreas....@gmail.com on 15 Aug 2011 at 7:08

@GoogleCodeExporter
Copy link
Author

Sorry, wrote too soon... shflags sets correctly __FLAGS_GETOPT_VERS to 
__FLAGS_GETOPT_VERS_STD (0)

Original comment by andreas....@gmail.com on 15 Aug 2011 at 7:26

@GoogleCodeExporter
Copy link
Author

Final comment, for anyone having the same issue on Mac OS X, you can get the 
enhanced GNU getopt version via MacPorts (http://www.macports.org/).

  $ sudo port install getopt
  (after you installed MacPorts, see http://www.macports.org/install.php)

Original comment by andreas....@gmail.com on 15 Aug 2011 at 7:41

@GoogleCodeExporter
Copy link
Author

it's not fixed

@andreas: shFlags's plot being "Most shell scripts use getopt for flags 
processing, but the different versions of getopt on various OSes make writing 
portable shell scripts difficult. shFlags instead provides an API that doesn't 
change across shell and OS versions so the script writer can be confident that 
the script will work."

I don't see how installing getopt from MacPorts is satisfying. The whole point 
of shFlags is to avoid relying on a specific version of getopt...

Original comment by gregory....@gmail.com on 8 Jan 2012 at 11:01

@GoogleCodeExporter
Copy link
Author

Opening until there is a reasonable native fix for OS X.

Original comment by kate.w...@forestent.com on 6 Jan 2013 at 5:15

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Any word on this? Yosemite is about to launch and this is still an issue.

Original comment by awelli...@gmail.com on 7 Oct 2014 at 4:37

@mahono
Copy link

mahono commented Jul 4, 2018

Hi, any news here? This still does not work on current MacOS (High Sierra) and it also does not work on my servers (DragonFlyBSD).

I'm using zsh.

@jblac
Copy link

jblac commented Jul 12, 2018

@mahono everything seems to work if you run brew install gnu-getopt and brew link --force gnu-getopt the default getopt doesn't play nice with long flags and shFlags - something that should be fixed, but installing the better version always works. Not sure the equivalent commands for macports or anything else as I don't use them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants