‘e’, ‘f’ and ‘g’ being the short options, ‘exit’, ‘follow’, ‘go’ the long options, and ‘param’ some parameter, I can not use ‘e’ as first - or only - option.
Let’s call the code above ‘test’.
$ test -e -f -g param
-f -g -- param
$ test -efg param
-f -g -- param
but
$ test -f -e -g param
-f -e -g -- param
$ test -feg param
-f -e -g -- param
I hope I’m missing something … otherwise it doesn’t make sense again. The long form ‘–exit’ works.
OK. I could look in getopt source and maybe find something weird. But I’m not trying to debug getopt. I just want to use "-e’ for ending a process in a script (other letters such as “-k”, “-q” and “-x” are already used for other options).
I normaly use ksh for scripts and then use print instead of echo.print has the same trap, but you can avoid it by using* - *or – as an end of options signal. echo does not seem to have such a feature.
henk@boven:~> exec ksh
henk@boven:/home/henk> print -a "lalala"
ksh: print: -a: unknown option
Usage: print -enprsvC] -f format] -u fd] [string ...]
henk@boven:/home/henk> print - -a "lalala"
-a lalala
henk@boven:/home/henk>
And as you see, print does object against unknown options, while echo just prints them as one of the strings:
henk@boven:~> echo -a "lalala"
-a lalala
henk@boven:~> echo -a -e "lalala"
-a -e lalala
henk@boven:~> echo -e -a "lalala"
-a lalala
henk@boven:~>
And the POSIX implementation of echo says:
The echo utility shall not recognize the “–” argument in the manner specified by Guideline 10 of the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines; “–” shall be recognized as a string operand.
Implementations shall not support any options.
Better, because your case is covered. but then you must use the POSIX one and not the default one.
Because it can’t be true. The quoting you show is a feature of the shell* (bash, ksh* and more of them). In this case there is nothing inside the quotes that is special to the shell. Thus the result after all the shell expansions are done is the same. And echo sees the same: a range of arguments where the firsts is* -e* and thus an option.
henk@boven:~> args="-e -a lalala"
henk@boven:~> echo $args
-a lalala
henk@boven:~>
I’m kind of confused with this stupid thread. I should just run less tests. I just wanted to pass all options (there were much more than in the example I posted) in order to discard conflicting options. I should have put $args in quote or use printf. But again, it was 6:00 AM, and I could not see anymore.