Welcome, guest | Sign In | My Account | Store | Cart
Version one...
Edit out as resquired...

#!/bin/bash

# An INKEY$ function for bash!
inkey() { char="" ; read -p "" -n1 -s -t1 char ; }
# Similar to BASIC's LET char$=INKEY$

# Do you remember INKEY$ in BASIC programming?
# Example:-
#
# PRINT "Some prompt:- "
# some_label:
# LET char$=INKEY$
# IF char$="<some_character>" THEN <do_something>
# IF char$="" THEN <do_something_else>
# GOTO some_label

# This is just a test piece only...
while true
do
	printf "Some prompt:- "
	# This is LET char$=INKEY$...
	inkey
	printf "$char...\n"
	if [ "$char" == "q" ]
	then
		printf "\nQuitting...\n\n"
		break
	fi
	if [ "$char" == "" ]
	then
		printf "Timeout works OK...\n"
	fi
	if [ "$char" == "b" ]
	then
		printf "Barry Walker...\n"
	fi
done



Version two...
Edit out as required...

#!/bin/bash

# Another INKEY$ function for bash!
inkey() { char="" ; stty -icanon min 0 time 1 ; char=`dd count=1 2> /dev/null` ; }
# Similar to BASIC's LET char$=INKEY$

# Do you remember INKEY$ in BASIC programming?
# Example:-
#
# PRINT "Some prompt:- "
# some_label:
# LET char$=INKEY$
# IF char$="<some_character>" THEN <do_something>
# IF char$="" THEN <do_something_else>
# GOTO some_label

while true
do
	printf "Some prompt:- "
	# This is LET char$=INKEY$...
	inkey
	printf "$char...\n"
	if [ "$char" == "q" ]
	then
		printf "\nQuitting... \n\n"
		break
	fi
	if [ "$char" == "" ]
	then
		printf "Timeout works OK...\n"
	fi
	if [ "$char" == "b" ]
	then
		printf "Barry Walker...\n"
	fi
done

Diff to Previous Revision

--- revision 1 2013-03-25 22:09:24
+++ revision 2 2013-03-28 17:51:32
@@ -1,3 +1,6 @@
+Version one...
+Edit out as resquired...
+
 #!/bin/bash
 
 # An INKEY$ function for bash!
@@ -20,10 +23,10 @@
 	printf "Some prompt:- "
 	# This is LET char$=INKEY$...
 	inkey
-	printf "Key pressed:- '$char'...\n"
+	printf "$char...\n"
 	if [ "$char" == "q" ]
 	then
-		printf "Quitting... \n"
+		printf "\nQuitting...\n\n"
 		break
 	fi
 	if [ "$char" == "" ]
@@ -35,3 +38,45 @@
 		printf "Barry Walker...\n"
 	fi
 done
+
+
+
+Version two...
+Edit out as required...
+
+#!/bin/bash
+
+# Another INKEY$ function for bash!
+inkey() { char="" ; stty -icanon min 0 time 1 ; char=`dd count=1 2> /dev/null` ; }
+# Similar to BASIC's LET char$=INKEY$
+
+# Do you remember INKEY$ in BASIC programming?
+# Example:-
+#
+# PRINT "Some prompt:- "
+# some_label:
+# LET char$=INKEY$
+# IF char$="<some_character>" THEN <do_something>
+# IF char$="" THEN <do_something_else>
+# GOTO some_label
+
+while true
+do
+	printf "Some prompt:- "
+	# This is LET char$=INKEY$...
+	inkey
+	printf "$char...\n"
+	if [ "$char" == "q" ]
+	then
+		printf "\nQuitting... \n\n"
+		break
+	fi
+	if [ "$char" == "" ]
+	then
+		printf "Timeout works OK...\n"
+	fi
+	if [ "$char" == "b" ]
+	then
+		printf "Barry Walker...\n"
+	fi
+done

History