Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»Bash Shell»How to Input Password in Shell Script as Hidden Characters

    How to Input Password in Shell Script as Hidden Characters

    By RahulNovember 1, 20171 Min Read

    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.

    Advertisement
    $ 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

    Related Posts

    Top 10 JQ Commands Every Linux Developer Should Know

    How to Check if a Program Exists in Linux

    How to Create a Directory If It Does Not Exist in Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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