- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Posix shell scripting... prompting for a response ...
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
Forums
Discussions
Discussions
Discussions
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
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
06-19-2002 11:59 AM
06-19-2002 11:59 AM
find / ! -fstype nfs -only -perm -o+w -type d | while read line; do
echo "Do you want to change permissions on file ${line## *}."
read answer
done
I understand why this doesn't give me the results I am looking for. The line "read answer" is loading the answer variable with the next line from the "find... " command.
How can I prompt for and read a response from the user blocking stdin from the "find .." command until I "read" a response from the user?
I thought putting a section of code withing parenthesis should fork a child process outside the influence of stdin from the parent process, but it does not appear that is the case.
Any ideas would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2002 12:13 PM
06-19-2002 12:13 PM
SolutionYou need to establish another file descriptor to accomodate the read within the loop.
#!/usr/bin/sh
exec 3<&0
while read LINE
do
echo $LINE
read -u3 REPLY
echo "you said $REPLY"
done < /etc/hosts
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2002 12:15 PM
06-19-2002 12:15 PM
Re: Posix shell scripting... prompting for a response from within a "while read" loop
To create variable using read command you need
\c at the end of your echo within quotes ""
Is that what you mean ? -
I had a little trouble understanding exactly what you are after
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2002 12:15 PM
06-19-2002 12:15 PM
Re: Posix shell scripting... prompting for a response from within a "while read" loop
Try this:
find / ! -fstype nfs -only -perm -o+w -type d | while read line; do
echo "Do you want to change permissions on file ${line## *}."
read answer <&1
done
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2002 12:16 PM
06-19-2002 12:16 PM
Re: Posix shell scripting... prompting for a response from within a "while read" loop
I have a favorite script that might solve your problem. The script has a function that takes yes/no input. You might do something like this:
# Get a yes/no answer to a question. Exit status 0 if "yes"
# Allow a -y or -n switch to give the default answer on just a newline
function getyesno
{
typeset ans
typeset default
if [[ ${1-} = -y ]] ; then default=0 ; shift ;
elif [[ ${1-} = -n ]] ; then default=1 ; shift ;
fi
while true
do
print -n >&2 "$@ "
read <&2 ans
case $ans in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
?*) ;;
*) # Answer was just
if [[ ! -z $default ]] ; then return $default ; fi
;;
esac
print >&2 " Please answer yes or no"
done
}
find / ! -fstype nfs -only -perm -o+w -type d | while read file
do
if $(getyesno -y "Do you want to change permissions on file $file [y]")
then
chmod o-w $file
fi
done
Or something like that.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2002 12:28 PM
06-19-2002 12:28 PM
Re: Posix shell scripting... prompting for a response from within a "while read" loop
In this case, the array subscripts could easily go beyond 1024 elements which made array usage a poor choice.
Thanks again!