Date: Mon, 20 Dec 1999 20:44:33 -0600 From: Jon Hamilton <hamilton@pobox.com> To: Ben Smithurst <ben@scientia.demon.co.uk> Cc: Salihin <odhienx@arwana.untan.ac.id>, Dan Larsson <dl@tyfon.net>, "[FreeBSD-Questions-List] (E-post)" <freebsd-questions@freebsd.org> Subject: Re: press any key to continue in sh Message-ID: <19991221024433.891113E@woodstock.monkey.net> In-Reply-To: Your message of "Mon, 20 Dec 1999 23:18:02 GMT." <19991220231802.A540@strontium.scientia.demon.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <19991220231802.A540@strontium.scientia.demon.co.uk>, Ben Smithurst
wrote:
} Salihin wrote:
}
} > On Mon, 20 Dec 1999, Ben Smithurst wrote:
} >
} >> Dan Larsson wrote:
} >>
} >>> How do I best produce a 'press any key to continue' prompt in sh?
} >>
} >> Try this:
} >>
} >> echo "Press any key to continue..."
} >> perl -e 'system("stty", "cbreak"); getc(STDIN); system("stty", "-cbreak");
} '
} >>
} >
} > or...
} > /bin/sh -c "read -p \"Press CTRL+C to abort and ENTER to continue !\" _e"
} > ^^^^^^
} > shell :-)
}
} So show me YOUR solution which implements what Dan asked for - "press
} any key to continue", not "press ENTER to continue". :-)
}
} Using perl may not be allowed, but it's the only way I can think of
} offhand. Unless Dan wants it implemented using shell builtin commands,
} I don't see anything wrong with my solution (higher overhead than I'd
} like, but still).
Well, this will be a little lower overhead and is more shell-ish:
#!/bin/sh
echon() {
if [ -n "`echo -n`" ] ; then
echo "$@\c"
else
echo -n "$@"
fi
}
echon "Press any key to continue: "
TTYSTATE=`stty -g`
stty raw
dd if=/dev/tty of=/dev/null bs=1 count=1 > /dev/null 2>&1
stty "$TTYSTATE"
echo
It's only good for interactive use, which may be ok given its nature :)
--
Jon Hamilton
hamilton@pobox.com
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991221024433.891113E>
