Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»Bash Shell»How to Input Password in Shell Script as Hidden Characters

    How to Input Password in Shell Script as Hidden Characters

    RahulBy RahulNovember 20, 20141 Min ReadUpdated:November 1, 2017

    Command:

    read -s -p “Enter Password: ” pswd

    How to Use:-

    If you want to take input of password in shell script. You must want to not to show any character on-screen entered by user. Use -s for silent mode. Using -s input characters are not echoed. For example create a shell script named inputpwd.sh and add following content.

    $ vim inputpwd.sh
    
    #!/bin/bash
    
    ### Input password as hidden charactors ### 
    read -s -p "Enter Password: "  pswd
    
    ### Print the value of pswd variable ### 
    echo -e "\nYour password is: " $pswd
    

    Let’s execute the script and enter your password, You just enter your password, characters will not display on-screen. This will work with /bin/bash shell only, older shell (/bin/sh) will throw an error.

    # chmod +x inputpwd.sh
    # ./inputpwd.sh
    
    Enter Password:
    Your password is:  9kjdfk329sksk
    
    input password read scripts shell
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to change Background Color of Text in Linux Shell
    Next Article How to Install .deb ile in Ubuntu & Debian

    Related Posts

    How to Backup Website to Amazon S3 using Shell Script

    Updated:March 24, 20222 Mins Read

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    Creating Menu in Shell Script (Linux Select Command)

    Updated:May 31, 20222 Mins Read

    (Resolved) -bash: /bin/mv: Argument list too long

    Updated:January 13, 20222 Mins Read

    Bash Break and Continue

    Updated:November 9, 20213 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    • How to Install Angular CLI on Ubuntu 22.04
    • How to Install Composer on Ubuntu 22.04
    • How to Create DMARC Record For Your Domain
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.