diff mbox series

[1/3] new: clean up the group name input code

Message ID 163183919544.953189.7870290547648551530.stgit@magnolia (mailing list archive)
State New, archived
Headers show
Series fstests: various cleanups to ./new script | expand

Commit Message

Darrick J. Wong Sept. 17, 2021, 12:39 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Clean up the code that reads group names in from the command line to
take advantage of the read command's ability to display a prompt.  While
we're at it, we should abort the script if the group list encounters
EOF, and we can tighten up some of the other sh-isms too.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 new |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Amir Goldstein Sept. 17, 2021, 10:28 a.m. UTC | #1
On Fri, Sep 17, 2021 at 12:57 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> From: Darrick J. Wong <djwong@kernel.org>
>
> Clean up the code that reads group names in from the command line to
> take advantage of the read command's ability to display a prompt.  While
> we're at it, we should abort the script if the group list encounters
> EOF, and we can tighten up some of the other sh-isms too.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>

> ---
>  new |   13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
>
> diff --git a/new b/new
> index 6b7dc5d4..ea7cf25e 100755
> --- a/new
> +++ b/new
> @@ -91,16 +91,13 @@ group_names() {
>         }' doc/group-names.txt
>  }
>
> -if [ $# -eq 0 ]
> -then
> -
> +if [ $# -eq 0 ]; then
> +       prompt="Add to group(s) [other] (separate by space, ? for list): "
>      while true
>      do
> -       echo -n "Add to group(s) [other] (separate by space, ? for list): "
> -       read ans
> -       [ -z "$ans" ] && ans=other
> -       if [ "X$ans" = "X?" ]
> -       then
> +       read -p "${prompt}" ans || exit 1
> +       test -z "${ans}" && ans=other
> +       if [ "${ans}" = "?" ]; then
>             echo $(group_names)
>         else
>             # only allow lower cases, spaces, digits and underscore in group
>
diff mbox series

Patch

diff --git a/new b/new
index 6b7dc5d4..ea7cf25e 100755
--- a/new
+++ b/new
@@ -91,16 +91,13 @@  group_names() {
 	}' doc/group-names.txt
 }
 
-if [ $# -eq 0 ]
-then
-
+if [ $# -eq 0 ]; then
+	prompt="Add to group(s) [other] (separate by space, ? for list): "
     while true
     do
-	echo -n "Add to group(s) [other] (separate by space, ? for list): "
-	read ans
-	[ -z "$ans" ] && ans=other
-	if [ "X$ans" = "X?" ]
-	then
+	read -p "${prompt}" ans || exit 1
+	test -z "${ans}" && ans=other
+	if [ "${ans}" = "?" ]; then
 	    echo $(group_names)
 	else
 	    # only allow lower cases, spaces, digits and underscore in group