1 . Which security protocol or measure would provide the greatest protection for a wireless LAN? WPA2 cloaking SSIDs shared WEP key MAC address filtering 2 . Refer to the exhibit. All trunk links are operational and all VLANs are allowed on all trunk links. An ARP request is sent by computer 5. Which device or devices will receive this message? only computer 4 computer 3 and RTR-A computer 4 and RTR-A computer 1, computer 2, computer 4, and RTR-A computer 1, computer 2, computer 3, computer 4, and RTR-A all of the computers and the router 3 . Refer to the exhibit. Hosts A and B, connected to hub HB1, attempt to transmit a frame at the same time but a collision occurs. Which hosts will receive the collision jamming signal? only hosts A and B only hosts A, B, and C only hosts A, B, C, and D only hosts A, B, C, and E 4 . Refer to the exhibit. Router RA receives a packet with a source address of 192.168.1.65 and a destination address of 192.168.1.161...
The simplest and most widely available method to get user input at a shell prompt is the 'read' command. The best way to illustrate its use is a simple demonstration:
ReplyDeletewhile true; do
read -p "Do you wish to install this program?" yn
case $yn in
[Yy]* ) make install; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
Another method, pointed out by Steven Huwig, is bash's 'select' command. Here is the same example using select:
echo "Do you wish to install this program?"
select yn in "Yes" "No"; do
case $yn in
Yes ) make install; break;;
No ) exit;;
esac
done
With select you don't need to sanitize the input... it prompts you with your choices, and you type a number corresponding to the choice you want. Select also loops automatically... there's no need for a 'while true' loop to retry if they give invalid input.
echo "Please enter some input: "
ReplyDeleteread input_variable
echo "You entered: $input_variable"
Since BASH4, you can now suggest an answer (-i), so the user only have to press return to enter it :
ReplyDeleteread -e -p "Enter the path to the file: " -i "/usr/local/etc/" FILEPATH
(remember to use the readline option (-e) to allow line editing with arrow keys)
Bash has select for this purpose.
ReplyDeleteselect result in Yes No Cancel
do
echo $result
done
read -p "Are you alright? (y/n) " RESP
ReplyDeleteif [ "$RESP" = "y" ]; then
echo "Glad to hear it"
else
echo "You need more bash programming"
fi
Use the read command
ReplyDeleteJust do:
echo Would you like to install? "(Y or N)"
read x
if [ "x" = "y"]
and then all of the other stuff you need
I suggest you use dialog... it's simple and easy to use, there's also a gnome version called gdialog that takes the exact same parameters, but shows it GUI style on X.
ReplyDeleteinquire () {
ReplyDeleteecho -n "$1 [$2/$3]? "
read answer
finish="-1"
while [ "$finish" = '-1' ]
do
finish="1"
if [ "$answer" = '' ];
then
answer=""
else
case $answer in
y | Y | yes | YES ) answer="y";;
n | N | no | NO ) answer="n";;
*) finish="-1";
echo -n 'Invalid response -- please reenter:';
read answer;;
esac
fi
done
}
... other stuff
inquire ""Install now? " "y" "n"
...
Where'd my formatting go? I guess that shows what happens if you cut and paste from unix text.
echo "Do you wish to install this program?"
ReplyDeleteselect yn in "Yes" "No"; do
case $yn in
Yes ) make install; break;;
No ) exit;;
esac
done`
Hi Christopher,
I used the above code in one of my bash script, even though it says select Yes or No it won't work if I press "Y" or "YES", rather I have to input "1" to say "YES" or 2 to say "NO", it does what it should on option "1" i.e. rm -rf filname (i am deleting a file after its downloaded and extracted) - once it has deleted it, it doesn't returns to the prompt rather it sits on ?#
Any ideas ? Your suggestions would be helpful
Thanks again !