Skip to content

Instantly share code, notes, and snippets.

@mobp
Created March 31, 2010 04:47
Show Gist options
  • Save mobp/349948 to your computer and use it in GitHub Desktop.
Save mobp/349948 to your computer and use it in GitHub Desktop.
標準入力からの一文字読み取り
# -s => サイレントモード
# -n => 読み取る文字数
read -s -n1 var
echo "$var"
#!/bin/sh
#シェルによる標準入力からの一文字読み取り(bsとcountの値で任意の文字数に変更できる)
getch()
{
stty raw
local c=$(dd bs=1 count=1 2>/dev/null)
stty cooked
echo "$c"
}
getch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment