Operating System - HP-UX
1835266 Members
2662 Online
110078 Solutions
New Discussion

Re: Is it possible to provide limits when reading a variable on a script

 
MAD_2
Super Advisor

Is it possible to provide limits when reading a variable on a script

If using ksh, and let's say for example in a script we'll want the user to enter a variable....

read NOTES ## Notes for table field.

But we also want to set a limit to the number of characters the user can type (let's say 40 max). Is there a way to do this with scripting?

Also, is there a way to set an underline, special character delimiters, or something like a background highlight to show the user on the shell his/her limits for typing?

Thanks for any ideas.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
5 REPLIES 5
Steve Steel
Honored Contributor

Re: Is it possible to provide limits when reading a variable on a script

Hi

look at man page and typeset option

|| typeset [+LRZfilrtux[n]] [name[ = value]] ...
Parameter assignments remain in effect after the
command completes. When invoked inside a function, a
new instance of the parameter name is created. The
parameter value and type are restored when the function
completes. The following list of attributes can be
specified:
-L Left justify and remove leading blanks from
value. If n is non-zero, it defines the
width of the field. Otherwise, it is
determined by the width of the value of first
assignment. When the name is assigned, the
value is filled on the right with blanks or
truncated, if necessary, to fit into the
field. Leading zeros are removed if the -Z
option is also set. The -R option is turned
off.
-R Right justify and fill with leading blanks.
If n is non-zero, it defines the width of the
field. Otherwise, it is determined by the
width of the value of first assignment. The
field is left-filled with blanks or truncated
from the end if the parameter is reassigned.
:


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
john korterman
Honored Contributor

Re: Is it possible to provide limits when reading a variable on a script

Hi,
try Jean-Louis Phelix' excellent answer in this thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x3b7b402f24d5d61190050090279cd0f9,00.html

regards,
John K.
it would be nice if you always got a second chance
MAD_2
Super Advisor

Re: Is it possible to provide limits when reading a variable on a script

Steve, thanks but no manual entry for typeset. John, I owe you points, I am still reading the very extensive number of comments in the link you provided. I hope to find the answer there, it looks very promising.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
James R. Ferguson
Acclaimed Contributor

Re: Is it possible to provide limits when reading a variable on a script

Hi Adam:

'typeset' is a shell built-in. See the man pages for 'sh-posix' for information on it.

Regards!

...JRF...
Steve Steel
Honored Contributor

Re: Is it possible to provide limits when reading a variable on a script

Hi


typeset is in the ksh


steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)