[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT:programmin questions



Lo, on Sunday, December 16, David Bellows did write:

<SNIP>

> The enclosed program will demonstrate what I have and give a basic
> idea of what I'm doing.  I am not a programmer as you'll quickly
> notice.

> #!/bin/sh
> while [ "$choice" != q ]
> do
> read choice
> case "$choice" in
>     a) /usr/local/bin/jac -P1;; #jac is a command line CD player
>     b) /usr/local/bin/jac -P5;;
>     c) /usr/local/bin/jac -k;;
>     #First kill the CD and then start DVD player
>     d) /usr/local/bin/jac -k; /usr/local/bin/ogle -u cli;; 
>     q) /usr/local/bin/jac -k;;
> esac
> done
> exit 0

It's about how I'd write something like this, and I *am* a programmer!
<grin>

> My problem is that I have to enter a key followed by ENTER.
> This is obviously cumbersome when using a remote control.  Does bash
> have a way around this?  Should I be using another language?  

Based on my reading of the bash man page (under the section defining the
`read' command), I don't think bash is going to do what you want.  In
particular, it says, "One line is read from the standard input, and the
first word is assigned to the first name [....]"  Because of the way
read splits on spaces, it has to read an entire line.  What I think Eric
Miller was alluding to in his post was the possibility of throwing the
terminal into `raw' mode, as opposed to the default `cooked' mode, so it
would pass all characters unchanged on to the application.  I don't
think this would work with bash; you'll need to use something else.

> If the latter, I would prefer, for now, a scripting language --
> thinking this would be easier to figure out as I need to learn new
> things.

I don't do this kind of stuff very frequently, so I'm not sure how one
would go about this in Perl, and I don't actually know any other
scripting languages (that are likely to be installed on your machine).

You actually can do this in bash, but you'll need some help reading the
input: a 4-line C program would do the trick.  There's almost certainly
a better way, though, so I won't post the code here.  If anyone's
interested, though, I'd be glad to send it along.

Richard



Reply to: