]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
docs(bash): remove section on optional args
authorIan Wienand <iwienand@redhat.com>
Mon, 28 Oct 2024 02:11:11 +0000 (13:11 +1100)
committerLaszlo <laszlo.gombos@gmail.com>
Fri, 1 Nov 2024 10:49:54 +0000 (06:49 -0400)
It's unclear under what circumstances these examples are appropriate and they
are somewhat conflicting with standard use of :+/+ in parameter expansions (see
the issue).

Rather than trying to be overally perscriptive about this, just remove it.  We
should make sure to add more explicit reasoning if we add things back in here.

Closes: https://github.com/dracut-ng/dracut-ng/issues/701
doc_site/modules/ROOT/pages/developer/bash.adoc

index 379b2ecdee12a4fbccebd9a33aab668f8b582219..8ad9f50bb9a2dce994aff4203d6227db78425eed 100644 (file)
@@ -156,92 +156,3 @@ if [[ ${!_drivers[*]} ]]; then
 fi
 ----
 
-== Optional parameters to commands
-
-If you want to call a command `cmd` with an option, if a variable is set, rather than doing:
-
-[,bash]
-----
-func() {
-  local param="$1"
-
-  if [[ $param ]]; then
-    param="--this-special-option $param"
-  fi
-
-  cmd $param
-}
-----
-
-do it like this:
-
-[,bash]
-----
-func() {
-  local param="$1"
-
-  cmd ${param:+--this-special-option "$param"}
-}
-
-# cmd --this-special-option 'abc'
-func 'abc'
-
-# cmd
-func ''
-
-# cmd
-func
-----
-
-If you want to specify the option even with an empty string do this:
-
-[,bash]
-----
-func() {
-  local -a special_params
-
-  if [[ ${1+_} ]]; then
-    # only declare `param` if $1 is set (even as null string)
-    local param="$1"
-  fi
-
-  # check if `param` is set (even as null string)
-  if [[ ${param+_} ]]; then
-    special_params=( --this-special-option "${param}" )
-  fi
-
-  cmd ${param+"${special_params[@]}"}
-}
-
-# cmd --this-special-option 'abc'
-func 'abc'
-
-# cmd --this-special-option ''
-func ''
-
-# cmd
-func
-----
-
-Or more simple, if you only have to set an option:
-
-[,bash]
-----
-func() {
-  if [[ ${1+_} ]]; then
-    # only declare `param` if $1 is set (even as null string)
-    local param="$1"
-  fi
-
-  cmd ${param+--this-special-option}
-}
-
-# cmd --this-special-option
-func 'abc'
-
-# cmd --this-special-option
-func ''
-
-# cmd
-func
-----