add listen-timeout to function as an accept timeout
[socat/sam.git] / readline-test.sh
blob2242ea9412284efad368719da26988c7fe61f3aa
1 #! /bin/bash
2 # source: readline-test.sh
3 # Copyright Gerhard Rieger 2003-2008
4 # Published under the GNU General Public License V.2, see file COPYING
6 # script that simulates a simple program with authentication.
7 # is just for testing the readline features
8 # perform the test with something like:
9 # ./socat readline,history=$HOME/.history,noecho='^Password: ' system:./readline-test.sh,pty,setsid,ctty,stderr,sigint,sigquit,echo=0,raw
12 BANNER='readline feature test program'
13 USERPROMPT='Authentication required\nUsername: '
14 PWDPROMPT='Password: '
15 PROMPT='prog> '
17 # degenerated user database
18 CREDUSER="user"
19 CREDPASS="password"
21 if [ $(echo "x\c") = "x" ]; then ECHO="echo"
22 elif [ $(echo -e "x\c") = "x" ]; then ECHO="echo -e"
25 #trap "$ECHO $0 got SIGINT" INT
26 trap "$ECHO $0 got SIGINT" INT
27 trap "$ECHO $0 got SIGQUIT" QUIT
29 # print banner
30 $ECHO "$BANNER"
32 # on (some) ksh read -p does not mean prompt
33 $ECHO "$USERPROMPT\c"; read -r USERNAME
34 $ECHO "$PWDPROMPT\c"; read -rs PASSWORD
35 $ECHO
37 if [ "$USERNAME" != "$CREDUSER" -o "$PASSWORD" != "$CREDPASS" ]; then
38 $ECHO "Authentication failed" >&2
39 exit -1
42 while $ECHO "$PROMPT\c"; read -r COMMAND; do
43 if [ "$COMMAND" = "exit" ]; then
44 break;
46 $ECHO "executing $COMMAND"
47 done