DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Sarosh Arif <sarosh.arif@emumba.com>
Cc: dev@dpdk.org, stable@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v1] usertools/dpdk-setup.sh: fix dpdk-setup's behaviour on non-alphanumeric inputs
Date: Thu, 19 Mar 2020 11:20:15 -0700	[thread overview]
Message-ID: <20200319112015.6e7d5f84@hermes.lan> (raw)
In-Reply-To: <20200319174423.28378-1-sarosh.arif@emumba.com>

On Thu, 19 Mar 2020 22:44:23 +0500
Sarosh Arif <sarosh.arif@emumba.com> wrote:

> Bugzilla ID: 419
> Cc: stable@dpdk.org
> Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
> ---
>  usertools/dpdk-setup.sh | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
> index e5bbe9fee..bdacf5256 100755
> --- a/usertools/dpdk-setup.sh
> +++ b/usertools/dpdk-setup.sh
> @@ -595,8 +595,14 @@ while [ "$QUIT" == "0" ]; do
>  	echo -n "Option: "
>  	read our_entry
>  	echo ""
> -	${OPTIONS[our_entry]} ${our_entry}
> -
> +	echo $our_entry | grep "^[0-9]*$" > /dev/null
> +
> +	if  [ "$?" -eq 0 ] ; then
> +		${OPTIONS[our_entry]} ${our_entry}
> +	else
> +		echo "Wrong input format"
> +	fi
> +
>  	if [ "$QUIT" == "0" ] ; then
>  		echo
>  		echo -n "Press enter to continue ..."; read


Why not do it with regex (abi check has similar code) and
use the nice format.

Also handle EOF

diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
index e5bbe9feec49..f594769a4ef1 100755
--- a/usertools/dpdk-setup.sh
+++ b/usertools/dpdk-setup.sh
@@ -592,10 +592,16 @@ while [ "$QUIT" == "0" ]; do
        echo "[$OPTION_NUM] Exit Script"
        OPTIONS[$OPTION_NUM]="quit"
        echo ""
-       echo -n "Option: "
-       read our_entry
+       read -p "Option: " our_entry
+       [ $? -eq 0 ] || exit 0
+
        echo ""
-       ${OPTIONS[our_entry]} ${our_entry}
+       numeric="^[[:digit:]]+$"
+       if [[ "$our_entry" =~ $numeric ]]; then
+               ${OPTIONS[our_entry]} ${our_entry}
+       else
+               echo "Please enter a numeric value"
+       fi

        if [ "$QUIT" == "0" ] ; then
                echo
--

      reply	other threads:[~2020-03-19 18:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19 17:44 Sarosh Arif
2020-03-19 18:20 ` Stephen Hemminger [this message]

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=20200319112015.6e7d5f84@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=sarosh.arif@emumba.com \
    --cc=stable@dpdk.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;
as well as URLs for NNTP newsgroup(s).