]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
docs: getopt: improve arg example in getopt-example
authorBen Song <bensongsyz@gmail.com>
Mon, 2 Mar 2026 13:48:25 +0000 (21:48 +0800)
committerKarel Zak <kzak@redhat.com>
Mon, 9 Mar 2026 11:42:11 +0000 (12:42 +0100)
The option `wow!*\?` in original example is not the argument of
`--c-long`. Only `=` separated in optional option is allowed.

[karelzak@redhat.com: - fix tcsh quote style to use backtick-quote
 matching actual script output, remove orphaned comment about
 exclamation mark escaping]

Based-on-patch-by: Ben Song <bensongsyz@gmail.com>
Addresses: https://github.com/util-linux/util-linux/pull/4088
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/getopt-example.bash
misc-utils/getopt-example.tcsh

index 78757ef6852cf610294f422ac014956da88c4b9c..1e267eb17eb85ae36330cc163258b0b343b3d579 100644 (file)
@@ -7,15 +7,25 @@
 
 # Example input and output (from the bash prompt):
 #
-# ./getopt-example.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long "
+# ./getopt-example.bash -a --a-long \
+#                       -barg_bs1 -b arg_bs2     --b-long=arg_bl1 --b-long arg_bl2 \
+#                       -carg_cs1 -c not_arg_cs1 --c-long=arg_cl1 --c-long not_arg_cl2 \
+#                       arg_p "string with quotes and space: '' \"\" "
 # Option a
+# Option a
+# Option b, argument 'arg_bs1'
+# Option b, argument 'arg_bs2'
+# Option b, argument 'arg_bl1'
+# Option b, argument 'arg_bl2'
+# Option c, argument 'arg_cs1'
+# Option c, no argument
+# Option c, argument 'arg_cl1'
 # Option c, no argument
-# Option c, argument 'more'
-# Option b, argument ' very long '
 # Remaining arguments:
-# --> 'par1'
-# --> 'another arg'
-# --> 'wow!*\?'
+# --> 'not_arg_cs1'
+# --> 'not_arg_cl2'
+# --> 'arg_p'
+# --> 'string with quotes and space: '' "" '
 
 # Note that we use "$@" to let each command-line parameter expand to a
 # separate word. The quotes around "$@" are essential!
index 094efa46fe163cb94961de501c62efcfe1d48d3d..8521c5f1f67dd2ef1a68c7b5b696f9d99b6d3e24 100644 (file)
@@ -6,20 +6,25 @@
 # as getopt-example.bash.
 
 # Example input and output (from the tcsh prompt):
-# ./getopt-example.tcsh -a par1 'another arg' --c-long 'wow\!*\?' -cmore -b " very long "
+# ./getopt-example.tcsh -a --a-long \
+#                       -barg_bs1 -b arg_bs2     --b-long=arg_bl1 --b-long arg_bl2 \
+#                       -carg_cs1 -c not_arg_cs1 --c-long=arg_cl1 --c-long not_arg_cl2 \
+#                       arg_p "string with quotes and space: '' \"\" "
 # Option a
+# Option a
+# Option b, argument `arg_bs1'
+# Option b, argument `arg_bs2'
+# Option b, argument `arg_bl1'
+# Option b, argument `arg_bl2'
+# Option c, argument `arg_cs1'
+# Option c, no argument
+# Option c, argument `arg_cl1'
 # Option c, no argument
-# Option c, argument `more'
-# Option b, argument ` very long '
 # Remaining arguments:
-# --> `par1'
-# --> `another arg'
-# --> `wow!*\?'
-
-# Note that we had to escape the exclamation mark in the wow-argument. This
-# is _not_ a problem with getopt, but with the tcsh command parsing. If you
-# would give the same line from the bash prompt (ie. call ./parse.tcsh),
-# you could remove the exclamation mark.
+# --> `not_arg_cs1'
+# --> `not_arg_cl2'
+# --> `arg_p'
+# --> `string with quotes and space: '' "" '
 
 # This is a bit tricky. We use a temp variable, to be able to check the
 # return value of getopt (eval nukes it). argv contains the command arguments