Required Bash Code for Hide Password during Typing [duplicate]












7















This question already has an answer here:




  • Reading passwords without showing on screen in Bash Scripts

    3 answers



  • How to take 'password' like input in shell script? [duplicate]

    3 answers




How can I write Bash Code for Hiding Password Or convert into '*'
user input will be in string so no spaces, and change or hide password String.










share|improve this question















marked as duplicate by muru, Jeff Schaller, RalfFriedl, roaima, Stephen Harris Dec 12 at 1:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    A string is a string even if it contains spaces, and passwords often contain spaces...
    – Kusalananda
    Dec 10 at 20:33










  • Oooph, tough call for me on VTC here. The target Q does have an answer that would print asterisks, as asked (in a comment) in this question, but it doesn't handle backspaces as also hinted at here. I'll VTC because it's a good duplicate otherwise, but if this question is edited to incorporate new requirements, it could become separate.
    – Jeff Schaller
    Dec 11 at 13:54
















7















This question already has an answer here:




  • Reading passwords without showing on screen in Bash Scripts

    3 answers



  • How to take 'password' like input in shell script? [duplicate]

    3 answers




How can I write Bash Code for Hiding Password Or convert into '*'
user input will be in string so no spaces, and change or hide password String.










share|improve this question















marked as duplicate by muru, Jeff Schaller, RalfFriedl, roaima, Stephen Harris Dec 12 at 1:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    A string is a string even if it contains spaces, and passwords often contain spaces...
    – Kusalananda
    Dec 10 at 20:33










  • Oooph, tough call for me on VTC here. The target Q does have an answer that would print asterisks, as asked (in a comment) in this question, but it doesn't handle backspaces as also hinted at here. I'll VTC because it's a good duplicate otherwise, but if this question is edited to incorporate new requirements, it could become separate.
    – Jeff Schaller
    Dec 11 at 13:54














7












7








7


1






This question already has an answer here:




  • Reading passwords without showing on screen in Bash Scripts

    3 answers



  • How to take 'password' like input in shell script? [duplicate]

    3 answers




How can I write Bash Code for Hiding Password Or convert into '*'
user input will be in string so no spaces, and change or hide password String.










share|improve this question
















This question already has an answer here:




  • Reading passwords without showing on screen in Bash Scripts

    3 answers



  • How to take 'password' like input in shell script? [duplicate]

    3 answers




How can I write Bash Code for Hiding Password Or convert into '*'
user input will be in string so no spaces, and change or hide password String.





This question already has an answer here:




  • Reading passwords without showing on screen in Bash Scripts

    3 answers



  • How to take 'password' like input in shell script? [duplicate]

    3 answers








linux bash password






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 10 at 17:37









Jeff Schaller

38.7k1053125




38.7k1053125










asked Dec 10 at 16:53









AlphaCoder

471




471




marked as duplicate by muru, Jeff Schaller, RalfFriedl, roaima, Stephen Harris Dec 12 at 1:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by muru, Jeff Schaller, RalfFriedl, roaima, Stephen Harris Dec 12 at 1:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    A string is a string even if it contains spaces, and passwords often contain spaces...
    – Kusalananda
    Dec 10 at 20:33










  • Oooph, tough call for me on VTC here. The target Q does have an answer that would print asterisks, as asked (in a comment) in this question, but it doesn't handle backspaces as also hinted at here. I'll VTC because it's a good duplicate otherwise, but if this question is edited to incorporate new requirements, it could become separate.
    – Jeff Schaller
    Dec 11 at 13:54














  • 1




    A string is a string even if it contains spaces, and passwords often contain spaces...
    – Kusalananda
    Dec 10 at 20:33










  • Oooph, tough call for me on VTC here. The target Q does have an answer that would print asterisks, as asked (in a comment) in this question, but it doesn't handle backspaces as also hinted at here. I'll VTC because it's a good duplicate otherwise, but if this question is edited to incorporate new requirements, it could become separate.
    – Jeff Schaller
    Dec 11 at 13:54








1




1




A string is a string even if it contains spaces, and passwords often contain spaces...
– Kusalananda
Dec 10 at 20:33




A string is a string even if it contains spaces, and passwords often contain spaces...
– Kusalananda
Dec 10 at 20:33












Oooph, tough call for me on VTC here. The target Q does have an answer that would print asterisks, as asked (in a comment) in this question, but it doesn't handle backspaces as also hinted at here. I'll VTC because it's a good duplicate otherwise, but if this question is edited to incorporate new requirements, it could become separate.
– Jeff Schaller
Dec 11 at 13:54




Oooph, tough call for me on VTC here. The target Q does have an answer that would print asterisks, as asked (in a comment) in this question, but it doesn't handle backspaces as also hinted at here. I'll VTC because it's a good duplicate otherwise, but if this question is edited to incorporate new requirements, it could become separate.
– Jeff Schaller
Dec 11 at 13:54










2 Answers
2






active

oldest

votes


















12














Use read -s to not echo the input, i.e. show nothing when the user types the password:



read -p 'Password? ' -s password
echo Your password is "$password".





share|improve this answer





















  • instead of hiding can i convert to character *
    – AlphaCoder
    Dec 10 at 17:00






  • 2




    Not so easily. You can read -n1 and display the asterisk yourself, though.
    – choroba
    Dec 10 at 17:04






  • 1




    @choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
    – ruakh
    Dec 11 at 0:20










  • @AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
    – chrylis
    Dec 11 at 8:00










  • @ruakh: Yes, that's part of the "not so easily".
    – choroba
    Dec 11 at 16:58



















10














You can use the systemd-ask-password, the password will displayed as asterisks while typing.



Format: (systemd-ask-password --help)



systemd-ask-password [OPTIONS...] MESSAGE


e,g:



PASSWORD=$(systemd-ask-password "Please type your Password:")
Please type your Password: ***********





share|improve this answer

















  • 1




    When I try this, I get bash: systemd-ask-password: command not found . . .
    – ruakh
    Dec 11 at 0:15


















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









12














Use read -s to not echo the input, i.e. show nothing when the user types the password:



read -p 'Password? ' -s password
echo Your password is "$password".





share|improve this answer





















  • instead of hiding can i convert to character *
    – AlphaCoder
    Dec 10 at 17:00






  • 2




    Not so easily. You can read -n1 and display the asterisk yourself, though.
    – choroba
    Dec 10 at 17:04






  • 1




    @choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
    – ruakh
    Dec 11 at 0:20










  • @AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
    – chrylis
    Dec 11 at 8:00










  • @ruakh: Yes, that's part of the "not so easily".
    – choroba
    Dec 11 at 16:58
















12














Use read -s to not echo the input, i.e. show nothing when the user types the password:



read -p 'Password? ' -s password
echo Your password is "$password".





share|improve this answer





















  • instead of hiding can i convert to character *
    – AlphaCoder
    Dec 10 at 17:00






  • 2




    Not so easily. You can read -n1 and display the asterisk yourself, though.
    – choroba
    Dec 10 at 17:04






  • 1




    @choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
    – ruakh
    Dec 11 at 0:20










  • @AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
    – chrylis
    Dec 11 at 8:00










  • @ruakh: Yes, that's part of the "not so easily".
    – choroba
    Dec 11 at 16:58














12












12








12






Use read -s to not echo the input, i.e. show nothing when the user types the password:



read -p 'Password? ' -s password
echo Your password is "$password".





share|improve this answer












Use read -s to not echo the input, i.e. show nothing when the user types the password:



read -p 'Password? ' -s password
echo Your password is "$password".






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 10 at 16:57









choroba

26.3k44772




26.3k44772












  • instead of hiding can i convert to character *
    – AlphaCoder
    Dec 10 at 17:00






  • 2




    Not so easily. You can read -n1 and display the asterisk yourself, though.
    – choroba
    Dec 10 at 17:04






  • 1




    @choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
    – ruakh
    Dec 11 at 0:20










  • @AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
    – chrylis
    Dec 11 at 8:00










  • @ruakh: Yes, that's part of the "not so easily".
    – choroba
    Dec 11 at 16:58


















  • instead of hiding can i convert to character *
    – AlphaCoder
    Dec 10 at 17:00






  • 2




    Not so easily. You can read -n1 and display the asterisk yourself, though.
    – choroba
    Dec 10 at 17:04






  • 1




    @choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
    – ruakh
    Dec 11 at 0:20










  • @AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
    – chrylis
    Dec 11 at 8:00










  • @ruakh: Yes, that's part of the "not so easily".
    – choroba
    Dec 11 at 16:58
















instead of hiding can i convert to character *
– AlphaCoder
Dec 10 at 17:00




instead of hiding can i convert to character *
– AlphaCoder
Dec 10 at 17:00




2




2




Not so easily. You can read -n1 and display the asterisk yourself, though.
– choroba
Dec 10 at 17:04




Not so easily. You can read -n1 and display the asterisk yourself, though.
– choroba
Dec 10 at 17:04




1




1




@choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
– ruakh
Dec 11 at 0:20




@choroba: I've just tested a bit, and -- it looks like using read -n1 for this has some sharply negative consequences, e.g. in that it's a lot of work to try to support backspace.
– ruakh
Dec 11 at 0:20












@AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
– chrylis
Dec 11 at 8:00




@AlphaCoder It is not idiomatic in Unix to display even the length of a password at the CLI.
– chrylis
Dec 11 at 8:00












@ruakh: Yes, that's part of the "not so easily".
– choroba
Dec 11 at 16:58




@ruakh: Yes, that's part of the "not so easily".
– choroba
Dec 11 at 16:58













10














You can use the systemd-ask-password, the password will displayed as asterisks while typing.



Format: (systemd-ask-password --help)



systemd-ask-password [OPTIONS...] MESSAGE


e,g:



PASSWORD=$(systemd-ask-password "Please type your Password:")
Please type your Password: ***********





share|improve this answer

















  • 1




    When I try this, I get bash: systemd-ask-password: command not found . . .
    – ruakh
    Dec 11 at 0:15
















10














You can use the systemd-ask-password, the password will displayed as asterisks while typing.



Format: (systemd-ask-password --help)



systemd-ask-password [OPTIONS...] MESSAGE


e,g:



PASSWORD=$(systemd-ask-password "Please type your Password:")
Please type your Password: ***********





share|improve this answer

















  • 1




    When I try this, I get bash: systemd-ask-password: command not found . . .
    – ruakh
    Dec 11 at 0:15














10












10








10






You can use the systemd-ask-password, the password will displayed as asterisks while typing.



Format: (systemd-ask-password --help)



systemd-ask-password [OPTIONS...] MESSAGE


e,g:



PASSWORD=$(systemd-ask-password "Please type your Password:")
Please type your Password: ***********





share|improve this answer












You can use the systemd-ask-password, the password will displayed as asterisks while typing.



Format: (systemd-ask-password --help)



systemd-ask-password [OPTIONS...] MESSAGE


e,g:



PASSWORD=$(systemd-ask-password "Please type your Password:")
Please type your Password: ***********






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 10 at 17:31









GAD3R

25.4k1750106




25.4k1750106








  • 1




    When I try this, I get bash: systemd-ask-password: command not found . . .
    – ruakh
    Dec 11 at 0:15














  • 1




    When I try this, I get bash: systemd-ask-password: command not found . . .
    – ruakh
    Dec 11 at 0:15








1




1




When I try this, I get bash: systemd-ask-password: command not found . . .
– ruakh
Dec 11 at 0:15




When I try this, I get bash: systemd-ask-password: command not found . . .
– ruakh
Dec 11 at 0:15



Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?