From owner-freebsd-questions Mon Dec 20 18:44:17 1999 Delivered-To: freebsd-questions@freebsd.org Received: from mailgw02.execpc.com (mailgw02.execpc.com [169.207.3.78]) by hub.freebsd.org (Postfix) with ESMTP id 1547B14D0B for ; Mon, 20 Dec 1999 18:44:14 -0800 (PST) (envelope-from hamilton@pobox.com) Received: from woodstock.monkey.net (planetx-2-16.mdm.mkt.execpc.com [169.207.119.144]) by mailgw02.execpc.com (8.9.1) id UAA01632; Mon, 20 Dec 1999 20:42:39 -0600 Received: from pobox.com (localhost [127.0.0.1]) by woodstock.monkey.net (Postfix) with ESMTP id 891113E; Mon, 20 Dec 1999 20:44:33 -0600 (CST) X-Mailer: exmh version 2.1.1 10/16/1999 To: Ben Smithurst Cc: Salihin , Dan Larsson , "[FreeBSD-Questions-List] (E-post)" Subject: Re: press any key to continue in sh In-reply-to: Your message of "Mon, 20 Dec 1999 23:18:02 GMT." <19991220231802.A540@strontium.scientia.demon.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 20 Dec 1999 20:44:33 -0600 From: Jon Hamilton Message-Id: <19991221024433.891113E@woodstock.monkey.net> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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