DISQUS

DISQUS Hello! Tech-Recipes is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Tech-Recipes

Cookbook of Tech Tutorials
Jump to original thread »
Author

Hide password entry in Bourne/bash shell script | Bourne shell scripting | Tech-Recipes

Started by qdideas · 9 months ago

No excerpt available. Jump to website »

5 comments

  • instead you can use -s option with read to hide the value like password

    read -s secret
  • Neat trick! Beware that this is OS dependent. It works on all the Linux flavors I've tried but not a Solaris 8 system. If you are writing a script to run on many platforms, the old school method above may be more generic. But if writing a script for a specific system, this is a much slicker method. Thanks for sharing!
  • I also add the protection for the interruptions:

    trap "stty echo ; exit" 1 2 15
    stty -echo
    read password
    stty echo
    trap "" 1 2 15

    If the user press Ctrl+C in the password prompt, the normal stty mode will be restored
  • Awesome! I've never used trap before, but I'll be using it from now on. That's a great solution to a very annoying problem. Thanks for sharing! Use of the trap command would make a great recipe..

    Q
  • One more thing (OS and shell-dependent):
    use closing redirection in the stty command:
    stty -echo >&- 2>&-

    This helps to avoid obsolete "No terminal" message in the scripts.

Add New Comment

Returning? Login