how can i know the pressed key is arrowup?

Hi all,
I need to know how to test a pressed key is arrowup or arrowdown and etc..
I found that the "echo" won't print anything if i enter the arrowup in the below code:

read 
echo "you pressed $REPLY"

Then i find a way to achieve my goal.

  1 #! /bin/bash
  2 
  3 ARROWUP='\[A'
  4 read
  5 echo $REPLY | grep -q $UP
  6 if [ $? -eq 0 ];then
  7    echo "you pressed arrowup"
  8 fi

problem is where can i find "ARROWUP" is shown as \[A because in my terminal the arrowup key is shown as [[A and i'm afraid i won't remember that someday.Any command to show that?

Maybe this is what you're looking for:

1 Like

Thanks,that works fine.But i still want to know where to find the information such as ARROWUP key is map to "\[A"?

$ exec ksh
$ set +o emacs vi
$ # now press up arrow key
$ ^[[A

Note that ^[ is the escape character. In that script \e also represents the escape character.

1 Like

Thanks all you guys!:b: