# |
Date |
Size |
|
Editor |
Comment |
Action |
119 |
2024-02-26 07:51:38 |
8323 |
to previous |
larryv |
replaced bash-hackers URL with Wayback Machine version |
view |
118 |
2021-08-03 18:27:03 |
8279 |
to previous |
GreyCat |
|
view |
117 |
2021-07-26 18:34:34 |
8281 |
to previous |
GreyCat |
Good riddance. |
view |
116 |
2021-07-26 10:52:51 |
8761 |
to previous |
JarnoSuni |
getopt from util-linux supports different styles of long options and options with mandatory and optional arguments. I have used it in my linux-purge script that is meant for Ubuntu Linux. |
view |
115 |
2021-07-26 02:19:37 |
8933 |
to previous |
GreyCat |
a -> an |
view |
114 |
2021-07-26 02:12:39 |
8932 |
to previous |
GreyCat |
Clarify. It's amazing how many people still misunderstand this. |
view |
113 |
2017-06-16 14:17:33 |
7751 |
to previous |
GreyCat |
|
view |
112 |
2017-06-16 14:07:52 |
7755 |
to previous |
GreyCat |
Explain a little more thoroughly. |
view |
111 |
2016-11-30 02:43:23 |
5476 |
to previous |
79 |
|
view |
110 |
2016-11-20 14:44:54 |
5482 |
to previous |
GreyCat |
move yet another crazy thing to ComplexOptionParsing |
view |
109 |
2016-11-19 14:41:40 |
7120 |
to previous |
213-211-57-37 |
fixed a typo |
view |
108 |
2016-11-19 14:40:01 |
7105 |
to previous |
213-211-57-37 |
Added mention about the Argbash utility (incorporated feedback from geirha) |
view |
107 |
2016-09-09 17:23:39 |
5482 |
to previous |
GreyCat |
Clean up the end. |
view |
106 |
2016-07-24 08:44:53 |
5697 |
to previous |
geirha |
this argbash.sh is rather poorly written; using uppercase variable names for internal purposes, missing quotes here and there, inconsistent use of syntax, not testing if cd fails. The list goes on. |
view |
105 |
2016-07-23 19:52:40 |
7247 |
to previous |
213-211-57-37 |
Added mention about the Argbash utility |
view |
- |
2016-07-23 19:45:37 |
2072 |
- |
213-211-57-37 |
ATTNEW: script.sh |
view get |
104 |
2016-02-04 20:23:10 |
5697 |
to previous |
geirha |
Options should not be mandatory/required, they should be *option*al. |
view |
103 |
2016-01-08 23:25:59 |
5765 |
to previous |
geirha |
no point in having this case in particular use continue |
view |
102 |
2015-06-18 19:52:05 |
5793 |
to previous |
GreyCat |
|
view |
101 |
2015-04-29 17:57:43 |
5822 |
to previous |
host-78-147-135-46 |
[igli] as greycat said in edit 87: "command shift" is silly # especially when you're using the vanilla form elsewhere. if your shell can't 'shift' you have bigger problems. |
view |
100 |
2015-04-11 08:25:27 |
5900 |
to previous |
geirha |
Replacing echos with printfs |
view |
99 |
2015-04-07 14:31:53 |
5888 |
to previous |
ormaaj |
And now it's -z! |
view |
98 |
2015-04-07 14:23:26 |
5888 |
to previous |
ormaaj |
Compromising on [ -n "$2" ] after discussion. Also we're not adding unnecessary set -u workarounds. Almost any example would need workarounds to function with it. Feel free to improve FAQ 112. |
view |
97 |
2015-04-07 05:38:57 |
5526 |
to previous |
a91-155-134-37 |
Don't try to evaluate an unset variable. Otherwise the script will exit with error, if set -u is used. |
view |
96 |
2015-04-07 00:19:02 |
5523 |
to previous |
ormaaj |
We want to test for a non-empty argument, not count the number of args. Most shells don't optimize $#. [ involves a pointless copy and some shells pass the -gt args to math evaluation on top of that. |
view |
95 |
2015-01-06 00:21:36 |
5537 |
to previous |
89 |
|
view |
94 |
2015-01-06 00:18:08 |
5541 |
to previous |
89 |
|
view |
93 |
2015-01-05 15:44:14 |
5539 |
to previous |
JarnoSuni |
This is much better programming practice than breaking by using undefined $1 or $2. |
view |
92 |
2015-01-05 14:03:23 |
5548 |
to previous |
ormaaj |
Remove all reference to set -u. It belongs in a dedicated FAQ which discusses what ${1+"$1"} is for, and all the many reasons to hate set -u. |
view |
91 |
2015-01-05 14:01:19 |
6147 |
to previous |
ormaaj |
Reverted. The script was perfect to begin with. I'd have done it last night but it looked like they were still editing. |
view |
90 |
2015-01-05 13:29:08 |
5539 |
to previous |
GreyCat |
OK, fine. You set -u people can have this battle. But not the war. You will NOT get to put set -u at the top of an example. Also, why did you add a second row of category tags, with a duplicate? |
view |
89 |
2015-01-04 23:36:49 |
5606 |
to previous |
JarnoSuni |
Make the script work even with set -o nounset (or set -u) |
view |
88 |
2014-08-07 09:52:57 |
6147 |
to previous |
geirha |
increment verbose |
view |
87 |
2014-07-15 18:18:00 |
6134 |
to previous |
GreyCat |
"command shift" is silly |
view |
86 |
2014-07-04 20:28:52 |
6142 |
to previous |
ormaaj |
Input validation for POSIX example. |
view |
85 |
2014-03-03 11:40:36 |
5776 |
to previous |
geirha |
Changing echos to printfs, and adding a usage function to the getopts example. |
view |
84 |
2014-03-03 09:14:40 |
5275 |
to previous |
geirha |
Manual loop and getopts is enough to answer this faq. Moved the rest to a separate page. |
view |
83 |
2014-02-28 08:36:45 |
12586 |
to previous |
proxy04 |
|
view |
82 |
2013-12-12 10:55:33 |
12584 |
to previous |
StephaneChazelas |
clarification about what POSIX specifies |
view |
81 |
2013-12-12 10:39:13 |
11850 |
to previous |
StephaneChazelas |
util-linux getopt is reliable when properly used. |
view |
80 |
2013-12-12 10:36:28 |
11791 |
to previous |
StephaneChazelas |
sorry, my bad about `-:` trick not working. reverting |
view |
79 |
2013-12-11 22:14:48 |
8324 |
to previous |
188-223-3-27 |
There's no getopts implementation where `-:` works to allow long options. |
view |
78 |
2013-05-06 07:42:24 |
11791 |
to previous |
geirha |
The quotes are unecessary and make it less consistent since not all such assignments were quoted. |
view |
77 |
2013-05-05 13:57:15 |
11795 |
to previous |
p5B0A11F9 |
Add quotes |
view |
76 |
2013-04-11 16:23:26 |
11791 |
to previous |
rrcs-67-52-129-61 |
fix typo |
view |
75 |
2013-03-14 14:15:08 |
11790 |
to previous |
Lhunath |
no need to check for --. |
view |
74 |
2013-02-05 20:38:19 |
11752 |
to previous |
GreyCat |
blank line makes the bot cry |
view |
73 |
2013-02-04 23:53:04 |
11754 |
to previous |
JarnoSuni |
OPTARG=(${@:OPTIND:$((longoptspec[$opt]))}) breaks arguments with whitespace. |
view |
72 |
2012-10-22 20:41:23 |
11126 |
to previous |
GreyCat |
Separate getops long option trickery into its own subsection. Also fix the counting in the set -u bit. |
view |
71 |
2012-09-12 11:59:53 |
11166 |
to previous |
52490F51 |
|
view |
70 |
2012-07-10 09:40:32 |
11163 |
to previous |
ormaaj |
geirha speaks the truth. |
view |
69 |
2012-07-10 03:37:14 |
11020 |
to previous |
S01060080adc182be |
${variable-} syntax |
view |
68 |
2012-05-11 05:31:08 |
10870 |
to previous |
free-vpn |
fixed number |
view |
67 |
2012-05-11 05:29:04 |
10870 |
to previous |
free-vpn |
fixed indention |
view |
66 |
2012-05-11 05:27:56 |
10874 |
to previous |
free-vpn |
fixed |
view |
65 |
2012-05-11 05:16:26 |
10754 |
to previous |
free-vpn |
Added more developed method to support long options alongside getopts |
view |
64 |
2012-02-03 21:44:39 |
9003 |
to previous |
GreyCat |
exit, not return, since it's no longer inside a function |
view |
63 |
2012-02-02 18:42:45 |
9005 |
to previous |
a91-155-176-245 |
Delete extra ending brace |
view |
62 |
2012-02-01 17:38:14 |
9008 |
to previous |
GreyCat |
Clean up... a lot. |
view |
61 |
2012-02-01 14:00:24 |
8991 |
to previous |
a91-155-176-245 |
Use --file as a better example of a required option |
view |
60 |
2012-02-01 13:55:20 |
9031 |
to previous |
a91-155-176-245 |
Move --verbose=VALUE alphabetically lower (after short option -v) |
view |
59 |
2012-02-01 13:53:22 |
9029 |
to previous |
a91-155-176-245 |
Fix --file option arg reading |
view |
58 |
2012-02-01 13:52:44 |
9029 |
to previous |
a91-155-176-245 |
Fix --file option's shift command |
view |
57 |
2012-02-01 13:51:44 |
9013 |
to previous |
a91-155-176-245 |
Order options alphabetically |
view |
56 |
2012-02-01 13:50:53 |
9013 |
to previous |
a91-155-176-245 |
Add also simple --file option example |
view |
55 |
2012-02-01 13:08:03 |
8855 |
to previous |
a91-155-176-245 |
Add eOF markers to complete scripts |
view |
54 |
2012-02-01 13:02:15 |
8838 |
to previous |
a91-155-176-245 |
Fix markup [[links]] |
view |
53 |
2012-02-01 12:58:45 |
8836 |
to previous |
a91-155-176-245 |
Fix spelling |
view |
52 |
2012-02-01 12:53:31 |
8835 |
to previous |
a91-155-176-245 |
Fix typo "the" => "then" |
view |
51 |
2012-02-01 12:52:43 |
8834 |
to previous |
a91-155-176-245 |
Remove Warn(), use plain echo |
view |
50 |
2012-02-01 12:49:38 |
8830 |
to previous |
a91-155-176-245 |
fix typo in word "everything" |
view |
49 |
2012-02-01 12:45:42 |
8829 |
to previous |
a91-155-176-245 |
Remove Die() |
view |
48 |
2012-02-01 12:42:26 |
8745 |
to previous |
a91-155-176-245 |
Add missing #!/bin/sh |
view |
47 |
2012-02-01 12:40:34 |
8732 |
to previous |
a91-155-176-245 |
Adjust case statement in code |
view |
46 |
2012-02-01 12:38:04 |
8730 |
to previous |
a91-155-176-245 |
Add missing {{{ markup |
view |
45 |
2012-02-01 12:36:56 |
8709 |
to previous |
a91-155-176-245 |
Trim down example and leave only option handling |
view |
44 |
2012-02-01 12:34:05 |
9933 |
to previous |
a91-155-176-245 |
Correct Copyrght line to official syntax: the placement of (C) |
view |
43 |
2012-02-01 12:21:20 |
9933 |
to previous |
a91-155-176-245 |
Add demonstration of how to use $verbose with Verbose() |
view |
42 |
2012-02-01 12:11:23 |
9691 |
to previous |
a91-155-176-245 |
Fis minor typo in option example |
view |
41 |
2012-02-01 12:10:25 |
9689 |
to previous |
a91-155-176-245 |
Replace separate "Manual options" examples with one POSIX example that also demonstrates --option ARG, and --option=ARG in one go. Add Bash highlighting etc other minor formatting. |
view |
40 |
2011-10-21 22:41:22 |
9215 |
to previous |
GreyCat |
add TOC |
view |
39 |
2011-10-19 06:17:52 |
9165 |
to previous |
pgas |
Remove the blank line, maybe fixing the TOC |
view |
38 |
2011-10-17 21:41:18 |
9167 |
to previous |
dslb-092-076-252-089 |
Can we regard the discussion as settled in this way? |
view |
37 |
2011-10-08 19:56:46 |
11098 |
to previous |
dslb-092-076-251-070 |
|
view |
36 |
2011-10-08 19:28:06 |
11625 |
to previous |
GreyCat |
explain more, although I thought I had already explained. what do you mean, you don't understand how your own trick works? |
view |
35 |
2011-10-08 15:56:56 |
10333 |
to previous |
dslb-092-076-251-070 |
|
view |
34 |
2011-10-08 15:28:45 |
9521 |
to previous |
dslb-092-076-251-070 |
There is more than one way to do it, since this section is titled getopts, I guess it fits here. It shows how to do it using getopts. The OPTERR-Stuff was just behavioural sugar, I just removed it |
view |
33 |
2011-10-08 02:09:20 |
9826 |
to previous |
GreyCat |
fix the "duh I used set -u and I broke it" "fix" which didn't actually work; what the hell is that getopts long options thing? |
view |
32 |
2011-10-07 18:32:45 |
9301 |
to previous |
dslb-092-076-251-070 |
|
view |
31 |
2011-10-07 18:30:36 |
9302 |
to previous |
dslb-092-076-251-070 |
|
view |
30 |
2011-10-07 18:28:14 |
9249 |
to previous |
dslb-092-076-251-070 |
Example for parsing long options with getopts |
view |
29 |
2010-07-27 16:01:37 |
7769 |
to previous |
Lhunath |
The grammar was correct. Admittedly, both sentences are linguistically ambiguous, though the original was better than the fix IMO. |
view |
28 |
2010-07-27 11:26:51 |
7773 |
to previous |
c122-108-89-15 |
|
view |
27 |
2010-06-11 20:19:38 |
7769 |
to previous |
geirha |
|
view |
26 |
2010-06-11 20:15:49 |
7764 |
to previous |
geirha |
Reset OPTIND before using getopts |
view |
25 |
2010-05-11 05:24:46 |
7757 |
to previous |
p5B09615D |
fixed links |
view |
24 |
2010-02-28 15:12:19 |
7766 |
to previous |
GreyCat |
make the "set -u" example much easier to read |
view |
23 |
2010-02-28 00:29:14 |
7382 |
to previous |
158 |
If you use "set -o nounset" (or "set -u"), the "manual loop" should be changed, since it finally can "work" with the value of an unset variable. |
view |
22 |
2010-02-28 00:16:52 |
6909 |
to previous |
158 |
Simplified a printf and sent the output to stderr. Added another 1>&2. |
view |
21 |
2010-02-28 00:12:12 |
6912 |
to previous |
158 |
Added "1>&2" to an error message |
view |