mkinitrd unification across distributions
 help / color / mirror / Atom feed
From: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	jstancek-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: [PATCH 1/2] add function getargnum
Date: Mon, 26 Nov 2012 10:38:47 +0800	[thread overview]
Message-ID: <20121126023847.GA6884@localhost.localdomain> (raw)



For cmdline argument with numeric value, add a new function getargnum
It will get proper value with default value as $1, max value as $2.
valid result will be echo to stdout, for nul or value not valid it will just
echo the default value.

Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 modules.d/99base/dracut-lib.sh |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

--- dracut.orig/modules.d/99base/dracut-lib.sh
+++ dracut/modules.d/99base/dracut-lib.sh
@@ -167,6 +167,25 @@ getargbool() {
     return 0
 }
 
+# getargnum <defaultval> <maxval> <args...>
+# Will echo the arg if it's in range [0 - maxval].
+# If it's not set or it's not valid, will set it <defaultval>.
+getargnum() {
+    local _b
+    unset _b
+    local _default
+    local _max
+    _default=$1; shift
+    _max=$1; shift
+    _b=$(getarg "$@")
+    [ $? -ne 0 -a -z "$_b" ] && _b=$_default
+    if [ -n "$_b" ]; then
+        [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
+        [[ $_b -ge 0 && $_b -le $_max ]] && echo $_b && return
+    fi
+    echo $_default
+}
+
 _dogetargs() {
     debug_off
     local _o _found _key

             reply	other threads:[~2012-11-26  2:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-26  2:38 Dave Young [this message]
     [not found] ` <20121126023847.GA6884-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-11-27 22:28   ` [PATCH 1/2] add function getargnum Vivek Goyal
     [not found]     ` <20121127222846.GF6964-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-28  5:51       ` Dave Young
2012-11-28  8:42   ` [PATCH 1/2 v2] " Dave Young
2013-01-11  9:59   ` [PATCH 1/2] " Harald Hoyer
     [not found]     ` <50EFE278.6040509-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-14  8:57       ` Dave Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121126023847.GA6884@localhost.localdomain \
    --to=dyoung-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=jstancek-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox