Operating System - HP-UX
1833875 Members
3113 Online
110063 Solutions
New Discussion

Re: Bourne Shell Programming Input and Output

 
SOLVED
Go to solution
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Thank you for your comments,

I give you a more documented script with some new features ... The usage will be :

getinput -u

Usage : getinput [-u] [-m max] [-n] [-e] [-f]

accept a string

-e : don't accept empty strings
-f : strings must have exact length
-m : max number of characters (default '4')
-n : filters non numeric characters
-u : usage

1) What if i want to enter alphanumeric how do i validate in your script?
You just have to delete 2 lines (or change the filter).

VAR=$(echo $VAR | tr -cd '[0-9.]')
[ -z "$VAR" ] && beep

In fact these lines suppress all chars except in the range 0 to 9 or '.'. So you could use for example [a-zA-Z0-9._] or suppress the lines to have no filter.

2) If there is more than 2 inputs:
Enter number : [0000] (4 numbers)
Enter name : [aaaaaaaaaaa] (11 alphabets)
Do i need to do validations for both the inputs or ?

You could easily modify the script to use parameters for MAX (max length) and FILTER (the filter string for 'tr')

3) If there is more than 10 inputs using this method, will it increase the unix uptime?

I don't think so ...

4) Which line of code disable the usage of crtl + c, ctrl + d, etc?

The stty command does it ('raw' flag)

Regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Dear Jean Louis Phelix, the comments are easy to understand esp the code that you attached with. Thanks a lot. I learn a lot from you. Do you know any way to create windows manager without xwindows using bourne shell (maybe tput)? Thank you.
wenching
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

Perhaps you could try keysh or tsm.

Regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

I had already man tsm but it did not teach me how to use tsm. When i run tsm i saw an error. View the attachment for the error. I had tried keysh before, but the problem here is i want to create a windows manager so i can integrate it into my bourne shell application. Any solution? Thank you.
wenching
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

You have to use a TERM for which you have a file '.fi' in /usr/tsm/term (for example alamost all vtxxx, hpterm, ...). Then use CTRL-T for menu.

Regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Dear Jean-Louis Phelix, i tried to access /usr/tsm/term it displays:
sh: /usr/tsm/term: Permission denied

but when i cd /usr, and cd tsm:
sh: tsm: not found.

Any idea? Is tsm is preconfigured in all HP-UX? The HP-UX 10.20 that we are using is not configured with xwindows? Is it related?

No other ways than using tsm? Thank you.
wenching
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

In fact /usr/tsm/term is only the directory where terminal descriptions are stored. tsm is installed on your system since you got the error 'cannot open ansi.fi'. So you should also have other terminal descriptions. Try a 'find / -name '*.fi' to locate these files (but they should be in /usr/tsm). If you need to reinstall them, they are in the product 'TerminalMngr' on the HP-UX CD.

Regards,

Jean-Louis.

It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

1) I think my org HP-UX 10.20 does not have any file with *.fi. I am very sad. Is there no other way to create a windows manager with commands other than tsm? Is it possible to call sam or cue interface? I think there is sure something store in the HP-UX where i call the interface. Anyway thanks for your help.

2) Dear Jean-Louis, i had tested your code but i had some confusion here where i try to apply your getinput concepts on multiple inputs. Example:

Enter name : [aaaaaaaaaa] (10 alphabets)
Enter student id : [aa0000] (6 alphanumeric)
Enter age : [00] (2 numbers)

I do not how to combine multiple inputs with one validation. Any sample script to show me. Thank you.
wenching
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

Here is an example of script which would use a modified version of previous getinput script as a "library" of function. I attached the modified getinput ...

----------------------------
#!/usr/bin/sh

. getinput

# get a mandatory (-e) string name (-s name)(alphbetical -a)
# max length 10 (-m 10) in variable NAME (-v NAME)
getinput_main -e -m 10 -a -s "name" -v NAME

# get a mandatory (-e) string student id (-s "student id" ) alphanumerical
# max length 6 (-m 6) fixed length (-f) in variable ID (-v ID)
getinput_main -e -m 6 -f -s "student id" -v ID
# get a mandatory (-e) string age (-s age)(numeical -n)
# max length 2 (-m 2) in variable AGE (-v AGE)
getinput_main -e -m 2 -n -s "age" -v AGE

echo "\n$NAME (id $ID) is $AGE years old\n"
----------------------------

Best regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Dear Jean-Louis Phelix, sorry for not replying as i was very busy with my projects lately.

I try the modified getinput, but when i run getinput -u, i did not see any output. Is there any problem with the modifed code? i had tried the old version but it is working.

Based on your previous reply:
#!/usr/bin/sh

. getinput

# get a mandatory (-e) string name (-s name)(alphbetical -a)
# max length 10 (-m 10) in variable NAME (-v NAME)
getinput_main -e -m 10 -a -s "name" -v NAME

# get a mandatory (-e) string student id (-s "student id" ) alphanumerical
# max length 6 (-m 6) fixed length (-f) in variable ID (-v ID)
getinput_main -e -m 6 -f -s "student id" -v ID
# get a mandatory (-e) string age (-s age)(numeical -n)
# max length 2 (-m 2) in variable AGE (-v AGE)
getinput_main -e -m 2 -n -s "age" -v AGE

echo "\n$NAME (id $ID) is $AGE years old\n"

Is that the command that i need to type in order to run this script. I had tried to change the scipt name to getinput_main but it ends up nothing.

Thanks for your help but what actually i want is able to enter more than 1 inputs at a time with your script? I think (i did not able to compile you script) your modified version is more on displaying the output with few variables.

Anyway thanks a lot. :D

wenching
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

perhaps my answer were not evry clear ... I gave you in my previous message a new release of the getinput script which can't be used anymore as a script, but now rather as a library of functions.

So you should write your own script (I gave you only an example) which would call my getinput. The line '. getinput' "includes" the functions defined in getinput into your script.

So the most simple example without comment could be a script named 'toto' :

#!/usr/bin/sh
. getinput
getinput_main -e -m 10 -a -s "name" -v NAME
getinput_main -e -m 6 -f -s "student id" -v ID
getinput_main -e -m 2 -n -s "age" -v AGE
echo "\n$NAME (id $ID) is $AGE years old\n"

the getinput_main function is now in the new getinput script. So if your PATH contains '.' just try to save my new getinput and this five lines script in the same directory, make them executable and run 'toto'.

Regards,

Jean-Louis.


It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Dear Jean-Louis Phelix:
-----------------------
I finally understand what you meant by the previous messages. About '.' (dot), is it something like import in java?

I just find out that i had a big major problem. As you can see, if i ask the end user to enter his/her name (names include spaces, example 'Chua Wen Ching' - 2 spaces), the script that you show me will not allow spaces ('ChuaWenChing').

How do you solve this situation? Thank you. :D
wenching
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Dear Jean-Louis Phelix, last time you recommended me to use tsm right. Can you show me some screenshots on tsm? So i will know how does tsm interface looks like? My org unix system does not contains tsm. Thank you.
wenching
harry d brown jr
Honored Contributor

Re: Bourne Shell Programming Input and Output


The manuak is no longer published, but maybe you can find it elsewhere:

Terminal Session Manager User's Guide
B2351-90000

Some other info:
http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html

live free or die
harry
Live Free or Die
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Thanks a lot. I had read the manual. But it doesn't show me how does a tsm looks like. Since my org unix cannot run tsm properly, got sample screenshots on tsm itself? Thank you.
wenching
harry d brown jr
Honored Contributor

Re: Bourne Shell Programming Input and Output


it looks like any other screen. The only difference is that you can use "ctrl-a" features to move between one session and another. There really isn't any terminal screen shots that are of any value.

Let's say you have define 4 sessions, and you are in session #2 and you start some very large compile job that's going to take hours, so once you start it, you can use the "ctrl-a4" feature to move to session 4. To move to session #1 you can either use ctrl-an (thats a control "a" then an "n" (not a control n)).

live free or die
harry
Live Free or Die
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

I had some problems with my 'tr ' command, so I changed the line and finally used the standard class filters. Blanks should now be accepted in alpha and alphanum. Try with this new 'getinput' but don't hesitate to modify my filters ...

Regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Dear Jean-Louis Phelix, with your new script, can i still use the script called "toto"? Or the getinput options had already change? I just want to confirm only. Thank you.
wenching
Jean-Louis Phelix
Honored Contributor

Re: Bourne Shell Programming Input and Output

Hello,

Nothing else than filters lines and tr line have changed, so you can still use toto ...

Regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
Chua Wen Ching
Regular Advisor

Re: Bourne Shell Programming Input and Output

Oic..it is cool. Only filters and tr. Anyway you really help me a lot. Thank you.
wenching