View Single Post
Old 03-28-2012, 03:37 PM   #21
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
One hint of something to check for in __any__ shell script -
The handling of whitespace.
More correctly, the handling of the "Input Field Seperator" character(s).

Often defined in the "IFS" variable and having the default of "space, tab, new-line" characters.

I can read where G.M. has dealt with space and new-line.
Perhaps tab (\x09) needs to be dealt with also?

Since this code is a shell function, and since most shell implementations recognize a function local setting of IFS -
Perhaps adding the pair of lines:

local IFS
IFS='some character you know will never show up in the key codes'

Will aid in dealing with the whitespace issues.

One hint about re-using G.M.'s function -

It is a function.
Add your code outside to the function and call the function from your added code passing the two expected parameters.

If running this function under Bash or Bash's sh mode -
You can pass any character (except \x00) by escaping it in the call.
I.E:
getkb $(printf '%q %q', parm-1, parm-2)
That will properly escape the two parameters at the point of the call and Bash's function argument processing will un-escape them.

For other sh implementations - a bit of experimenting might be required.
knc1 is offline   Reply With Quote