Operating System - HP-UX
1753587 Members
7030 Online
108796 Solutions
New Discussion юеВ

Not allowing ENTER as an option

 
TheJuiceman
Super Advisor

Not allowing ENTER as an option

Hello everyone,

I have written a script that asks the user for input. I want to make it so that the user cannot simply hit the ENTER key to the input to continue. How can I do this? Thanks.
9 REPLIES 9
Florian Heigl (new acc)
Honored Contributor

Re: Not allowing ENTER as an option

this as close as I can get - he can press enter, but it won't be accepted.

while [ "X$input" = "X" ]
do
echo "Don't press enter, type something"
read input
done

I looked through stty -a, maybe defineing
stty eol does the trick, but I'm not sure.
(Wait for someone else's opinion on that)

If the users are connecting with a graphics-enabled terminal (hpterm, dtterm, putty, ...) You could use ncurses.

A friend of mine also wrote a shell widget library, but I don't find his cvs-web site right now, so no access to that, but I'll try to add it tomorrow.
yesterday I stood at the edge. Today I'm one step ahead.
Victor Fridyev
Honored Contributor

Re: Not allowing ENTER as an option

Hi,
I usualy do the following in sh/ksh:

while true; do
echo "Please answer "
read INP
case $INP in
A) doA;break;;
B) doB;break;;
C) doC;break;;
*) echo "Invalid answer <$INP>"
esac
done

HTH
Entities are not to be multiplied beyond necessity - RTFM
harry d brown jr
Honored Contributor

Re: Not allowing ENTER as an option

Ask questions that require a Y or N, and intermix them. Back in the days when I wrote code for banks we used to ask the operator at least 10 questions, randomly, with mixed responses (at least one Y or N in the sequence) required to really continue.

Here's a simple sample:

Do you want to continue
Would you like to stop now


The funny thing is that if they are bright they could use tck/tl to fool you!


live free or die
harry d brown jr
Live Free or Die
TheJuiceman
Super Advisor

Re: Not allowing ENTER as an option

Thank you for the suggestions. However, I cannot make a bullet list of objects because it is to allow a programmer to su as another person (being done in restricted sam). The list of users changes daily and there are hundreds of them. If they simply hit the ENTER key, they will su as root. And I do not want to use su-do for this function. There has to be a way to accept a typed in response and disallow a blank ENTER response.
Gordon  Morrison
Trusted Contributor

Re: Not allowing ENTER as an option

Try something like this:

input=""
while true
do
read input?"Please type something... "
if [[ -z $input ]]
then
echo "You cannot enter a blank line!"
else
echo "thank you"
break
fi
done
What does this button do?
Florian Heigl (new acc)
Honored Contributor

Re: Not allowing ENTER as an option

this won't work that easy - if he doesn't type but a few blanks, he'll be root anyhow.

neither my string-compare nor test -z prohibit this.

please consider a different way of doing this.

for example, /etc/default/security has the option SU_ROOT_GROUP which could be set to =wheel , then only users which are members of the wheel group will be able to become root. (wheel is the de-facto standard name for that thingy)
yesterday I stood at the edge. Today I'm one step ahead.
derek b smith_1
Regular Advisor

Re: Not allowing ENTER as an option

I have used with success after testing myself on HPUX 11.0 and 11i
stty -brkint and
stty -isig
TheJuiceman
Super Advisor

Re: Not allowing ENTER as an option

Thank you all again for the posts.

As you can tell, script writing is not my "area of expertise". I do not have a trusted system (due to some software issues) and do not have a /etc/default/security file. I am also a bit unsure how to use the "stty" commands.

I did have an idea however. If I redirected a ls of /home into a file, could I write a script that will only allow them to pick something that is in that file? Thanks again for your help.
TheJuiceman
Super Advisor

Re: Not allowing ENTER as an option

With the help of some people on the "general" board, I think I've found something that works. It will allow a user to su as another user inside restricted sam without become root or its equivalent. It also will prevent them from simply hitting the ENTER key or some spaces to become root. Since there are no services or root logins in the /home directory, this seems to work really well.

echo "\n\n Please enter the user ID that you want to assume: \c"
ls /home > /tmp/TEMP
while true
do
read INPUT
[[ "a$INPUT" = "a" ]] && continue
grep -q $INPUT /tmp/TEMP
[[ $? !=0 ]] && echo "\n\n Access denied." && exit
break
done
su - $INPUT
rm /tmp/TEMP
exit

Thanks...Bob