- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- question on scripting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 01:41 AM
тАО03-31-2006 01:41 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 01:44 AM
тАО03-31-2006 01:44 AM
Re: question on scripting
echo "enter yes or no"
read ANSWER
You can then test the variable for "yes" or "no".
Pete
Pete
- Tags:
- read
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 01:46 AM
тАО03-31-2006 01:46 AM
Re: question on scripting
This will do what you are looking for.
read answer
if [ $answer = "Y" ]
then
do this
else
do this
fi
You can also use case statment.
Hope this helps.
Shahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 01:47 AM
тАО03-31-2006 01:47 AM
Re: question on scripting
#/usr/bin/sh
echo "Say something"
read REPLY
echo "You said ${REPLY} ...thank you!"
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 01:51 AM
тАО03-31-2006 01:51 AM
Re: question on scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 02:13 AM
тАО03-31-2006 02:13 AM
SolutionThe 'read' waits for input.
#!/usr/bin/sh
typeset -l REPLY
echo "Answer 'y' or 'n' \c"
read REPLY
while [ "${REPLY}" != "y" -a "${REPLY}" != "n" ]
do
echo "Please answer 'y' or 'n'"
read REPLY
done
echo "You replied '${REPLY}' -- thanks!"
exit 0
...In the above script we keep asking for a REPLY until the user responds with a "y" or an "n". The 'typeset -l' causes the contents of the REPLY variable which is filled by the 'read' to be translated to lowercase letters. This makes the comparisons for a proper response easy.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 02:21 AM
тАО03-31-2006 02:21 AM
Re: question on scripting
1) You have redirected stdin.
2) There are already characters in the input buffer so the reply is being satisfied from the buffer.
3) No read permission on the stdin device.
4) You have changed the terminal characterics so that it times out if no characters are available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 02:25 AM
тАО03-31-2006 02:25 AM
Re: question on scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 02:32 AM
тАО03-31-2006 02:32 AM
Re: question on scripting
If you are issuing a 'read' to collect a user's input and are already reading a file, you will need to use *separate* file descriptors to keep the data segregated.
#!/usr/bin/sh
exec 3<&0
cat /etc/hosts | while read LINE
do
echo "${LINE}"
read -u3 REPLY
echo "You said ${REPLY}"
done
If the above example, I'm reading LINEs from the '/etc/hosts file; echoing them to STDOUT; and *read*ing from STDIN into the REPLY variable. The 'read -u' variation says that I want that read to be from file descriptor #3 which is a duplicate of descriptor zero (0) [STDIN] the beginning of the script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2006 02:35 AM
тАО03-31-2006 02:35 AM
Re: question on scripting
read REPLY <&2
This will force read to read from STDERR which should still be assigned to your terminal.
Or if STDERR is redirected, then you can use-
read REPLY
HTH
-- Rod Hills