Skip to content

Commit

Permalink
new: clean up the group name input code
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Amir Goldstein <[email protected]>
Signed-off-by: Eryu Guan <[email protected]>
  • Loading branch information
Darrick J. Wong authored and guaneryu committed Sep 26, 2021
1 parent 797dcac commit 6fe95af
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions new
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6fe95af

Please sign in to comment.