읽기 명령의 -s 매개변수가 출력을 엉망으로 만듭니다.

읽기 명령의 -s 매개변수가 출력을 엉망으로 만듭니다.

그래서 내 사용자가 스크립트를 다시 추가했고 읽기 명령에 -s 인수가 있는 경우(암호를 가져올 때) 출력이 왜곡되는 것을 발견했습니다.

코드는 다시 다음과 같습니다.

#!/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

그래서 이것이 여기에 있는 동안:

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

다음과 같이 출력됩니다.

[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:

이것은 잘 작동하지만 -s 매개변수가 있는 경우:

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

출력은 다음과 같습니다.

[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:

그래서 내 질문은 여기에 있습니다 :

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

이것이 정말 작은 일이라는 것을 알지만, 왜 이런 일이 발생하는지, 그리고 가능하다면 어떻게 피할 수 있는지 아는 것이 좋을 것입니다.

감사해요.

답변1

이것이 견고한지는 확실하지 않지만 시도해 보십시오.

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

관련 정보