나는 이미 이 질문을 했고 이제 또 다른 질문이 생겼습니다. 이것은 내 코드입니다.
#! /bin/bash
read -p 'Username:' name
read -p 'Password:' pass
echo
echo Confirm Username: $name?
echo "Confirm Password: ${pass//?/*}"
echo Let us start the quiz :P
echo
echo Q1 - Full form of MCQ
echo a - Maximum Capture Quest
echo b - Multiple Choice Question
read -p "Your Answer:" word
if [[ $word == "b" ]]
then
echo "Correct! V.Good"
else
echo "Wrong. U Suck"
fi
read -p 'Password:' pass
입력의 이 부분( )을 별표로 표시하고 싶습니다 .
답변1
별표로 입력된 에코 문자? Jon Red가 1위를 차지했지만 여기에 또 다른 것이 있습니다.
#!/bin/bash
# read a string, prompting using "$1"
# echo characters entered as asterisks
# value is returned in variable `pass`
readpw() {
printf "%s" "${1-}"
pass=
local char
while IFS= read -r -s -n1 char; do
if [[ $char = "" ]] ; then
# enter, end
printf "\n"
break
elif [[ $char = $'\177' ]] ; then
# backspace, remove one char
if [[ $pass != "" ]] ; then
pass=${pass%?}
printf '\b \b'
fi
else
# any other char
pass+=$char
printf "*"
fi
done
}
readpw "Enter Password: "
printf "Password entered was: %s\n" "$pass"
답변2
어쩌면 이런 게 있지 않을까요?
#! /bin/bash
read -p 'Username:' name
# read -p 'Password:' pass
unset pass
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
break
fi
prompt='*'
pass+="$char"
done
echo
echo Confirm Username: $name?
echo "Confirm Password: ${pass//?/*}"
echo Let us start the quiz :P
echo
echo Q1 - Full form of MCQ
echo a - Maximum Capture Quest
echo b - Multiple Choice Question
read -p "Your Answer:" word
if [[ $word == "b" ]]
then
echo "Correct! V.Good"
else
echo "Wrong. U Suck"
fi