Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving input from keyboard

Status
Not open for further replies.

sl33pyon3

Technical User
May 8, 2003
5
US
I need to recieve some input from a keyboard after a user logs in from a ssh connection.

This is the only thing I have so far:

echo "Welcome"
echo "Which project number do you want to work on?"
answer={input from keyboard} #Not sure what to put here

Any help with this would be greatly appreciated.

Thank you in advance!
 
[tt]read answer[/tt] would put the user input in [tt]$answer[/tt].

//Daniel
 
echo "Welcome"
echo "Which project number do you want to work on?"

read ANSWER


echo "You will now be put into project Number ${ANSWER}"



Try that


As always we thank you for your support
Doug
 
ok, that worked for me thank you but the rest of my script won't continue. If you don't mind, I'm going to post the complete script. If you could point out my dumbness to me I would appreciate it.

replies = 0


get_proj:
clear
echo
echo " * * * Quancept * * *"
echo
echo
echo "What project are you working on? "
#Works great
read answer

#Just checking
echo "${answer}"
if (! -d /home/spssmr/"${answer}") then
echo "There is no such project as ${answer}"
${replies} = ${replies} + 1
if (${replies} < 3) goto get_proj
echo &quot;Please check the project number again.&quot;
echo &quot;I cannot find the project you gave me.&quot;
else logout
else cd /home/spssmr/&quot;${answer}&quot;
endif
 
ok here is my revised code:

declare -i replies=0

proj(){

#clear the screen to present the menu
clear

#Start of menu
echo
echo &quot; * * * Quancept * * *&quot;
echo
echo
echo &quot;What project are you working on? &quot;
read answer
if (cd /home/spssmr/&quot;${answer}&quot;); then
qtip {$answer};

else proj1;

fi

}

proj1(){
echo &quot;There is no such project ${answer}&quot;;
echo &quot;Press Enter to retype the project name&quot;;
let replies=replies+1;
echo ${replies}; #just checking the count
read hold; #needed to be able to read count
if (replies>3); then
echo &quot;Please contact your Supervisor and get the correct project please&quot;;
echo &quot;Press Enter to close this window&quot;;
read hold; #Needed to let user read previous statement
logout;
else proj;
fi

}

proj


The problem I am now having is that it never seems to go through my &quot;if (replies>3)&quot; statement. Any ideas?

Thank you again!
 
[tt]if[/tt] statements use brackets ([tt][[/tt] and [tt]][/tt]), not parenthesis.

//Daniel
 
ok, I'll try that also, but in the meantime while I was waiting this is what I did and it seems to work pretty well:

declare -i replies=0

proj(){

#clear the screen to present the menu
clear

#Start of menu
echo
echo &quot; * * * Quancept * * *&quot;
echo
echo
echo &quot; What project are you working on? &quot;
read answer
if (cd /home/spssmr/&quot;${answer}&quot;); then
qtip {$answer};
stop;
else proj1;

fi
}

proj1(){
let replies=replies+1

case &quot;${replies}&quot; in

&quot;4&quot; )
clear
echo
echo &quot; Please contact your Supervisor and get the correct project please&quot;
echo &quot; Press Enter to close this window&quot;
read hold
logout
;;

*)

echo
echo
echo &quot; There is no such project ${answer}&quot;
echo &quot; Press Enter to retype the project name&quot;
read hold
proj
;;

esac
}
proj
 
Parenthisis are used to create a list of commands. For example, [tt]( echo -n &quot;Hello &quot; && echo &quot;World!&quot; ) > filename[/tt] would put [tt]Hello World![/tt] into [tt]filename[/tt].

//Daniel
 
Well I made a few changes but this should work for you.


#!/usr/bin/ksh

replies=0
################
proj()
################
{
#clear the screen to present the menu
clear
#Start of menu
echo
echo &quot; * * * Quancept * * *&quot;
echo
echo
echo &quot; What project are you working on? &quot;
read answer

#Use only one of the following
if [ -d /home/spssmr/${answer} ]; then # for checking if directory exists
if [ -d /home/spssmr/${answer} ]; then #for checking if file exisits

qtip {$answer}
exit
else
proj1
fi
}
################

################
proj1()
################
{
let replies=${replies}+1
case ${replies} in

&quot;4&quot; )
clear
echo
echo &quot; Please contact your Supervisor and get the correct project please&quot;
echo &quot; Press Enter to close this window&quot;
read hold
exit
;;
*)

echo
echo
echo &quot; There is no such project ${answer}&quot;
echo &quot; Press Enter to retype the project name&quot;
read hold
proj
;;

esac
}
################
proj


As always we thank you for your support
Doug
 
Hi,
I'm a few days late for this thread, but I just couldn't resist. Over the years, I've written many scripts to do this sort of thing, so here's one-more-way-to-do-it.

My assumptions:
1. User is logged out if they don't select a project.
2. Why have retries? If user already logged in, then they are valid.
3. This is a login script (otherwise the 'cd' will be lost when the script ends).
-cheers.


#!/usr/bin/bash
base=&quot;/home/spssmr&quot;
while : ; do
/bin/echo -n &quot;\nEnter Project (* for List, RETURN to exit) :&quot;
read project
if [ &quot;$project&quot; = &quot;&quot; ]; then
logout
fi
if [ &quot;$project&quot; = &quot;*&quot; ]; then
ls $base
continue
fi
if [ -d $base/$project ]; then
cd $base/$project
break
fi
echo &quot;No such project - try again.&quot;
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top