简体   繁体   中英

How to 'read -s' in shell?

I know that user input can be read silently using bash with read -s someVar and I was wondering if there is a /bin/sh equivalent that allows user input without displaying it on the command line?

Note: I am just curious if /bin/sh read supports this feature somehow.

Use the stty command to turn off echoing of typed characters.

get_entry () {
  printf "Choose: "
  stty -echo
  IFS= read -r choice
  stty echo
  printf '\n'
}

get_entry

printf "You chose %s\n" "$choice"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM