O argumento -s para o comando read desordena a saída

0

Então, meu usuário adicionando script novamente, notei que, se eu tiver o argumento -s para o comando read (ao obter a senha), a saída fica confusa.

Este é o código novamente:

#!/bin/bash
# Only works if you're root

for ((a=1;a>0;a)); do
 if [[ "$UID" -eq 0 ]]; then
  echo "Quit this shit anytime by pressing CTRL + C"
  read -p 'Enter one usernames: ' USERNAME
  nrchar=$(echo ${#USERNAME})
#  echo $nrchar
  spcount=$(echo ${USERNAME} | tr -cd ' ' | wc -c)
#  echo $spcount
  if [[ "${nrchar}" -gt 8 ]]; then
    echo "You may not have more than 8 characters in the username"
   elif [[ "${spcount}" -gt 0 ]]; then
    echo "The username may NOT contain any spaces"
   else
     read -p 'Enter one names of user: ' COMMENT
     read -p 'Enter one passwords of user: ' PASSWORD
     useradd -c "${COMMENT}" -m ${USERNAME}
#     echo "${?}"
     if [[ "${?}" -ne 0 ]]
     then
       echo "Username could not be created"
     else
      echo ${PASSWORD} | passwd --stdin ${USERNAME}
      passwd -e ${USERNAME}
     fi
   fi
 echo "------------------------------------------------------"
 else
  echo "You're not root, so GTFO!"
  a=0
 fi
done

Então, enquanto isso está aqui:

     read -p 'Enter one passwords of user: ' PASSWORD

Isso gera isso:

[vagrant@localhost vagrant]$ sudo ./exercise2-stuffs.sh
Quit this shit anytime by pressing CTRL + C
Enter one usernames: user88
Enter one names of user: user
Enter one passwords of user: 88
Changing password for user user88.
passwd: all authentication tokens updated successfully.
Expiring password for user user88.
passwd: Success
------------------------------------------------------
Quit this shit anytime by pressing CTRL + C
Enter one usernames:

O que é bom, mas se eu tiver o argumento -s:

     read -s -p 'Enter one passwords of user: ' PASSWORD

A saída é assim:

[vagrant@localhost vagrant]$ sudo ./exercise2-stuffs.sh
Quit this shit anytime by pressing CTRL + C
Enter one usernames: user00
Enter one names of user: user
Enter one passwords of user: Changing password for user user00.
passwd: all authentication tokens updated successfully.
Expiring password for user user00.
passwd: Success
------------------------------------------------------
Quit this shit anytime by pressing CTRL + C
Enter one usernames:

Então, meu problema está aqui:

Enter one passwords of user: Changing password for user user00.

Eu sei que é algo realmente insignificante, mas ainda assim, seria bom saber por que isso acontece, e se é evitável, como eu poderia evitá-lo?

Obrigado.

    
por iamAguest 20.08.2018 / 17:04

1 resposta

0

Não tenho certeza se isso é sólido, mas tente

read -s -p 'Enter one passwords of user: ' PASSWORD; echo
    
por 20.08.2018 / 17:43