[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash Script - Reading User Input while Processing output from Command within Bash
I am trying to get a users input by using read -p method while it inside a loop which is processing an output from a command by using read -r method. read -p method does not work it seems to be still reading data from the output from the command. any ideas?
Code:
while read -r LLINE; do
echo `echo $LLINE | awk -F '[:]' '{print $1}'`
echo 'Do You Want To Delete,Archive or Skip this file'
echo 'Type (D|A|S) and press enter'
read -p "Do You Want To Delete,Archive or Skip this file (D|A|S) ?" Responce
case $Responce in
[Dd]*) #delete the file
;;
[Aa]*) #Archive the file
;;
*) # Skip File
;;
esac
done < <(find -P $HomeDirPath -size +$MaxSize\k -type f -printf "%h/%f:%s\n")
Last edited by cleeky; 05-22-2014 at 02:32 PM.
Reason: Made the COdes Section small to make it clearer
both «read» commands work with the same file descriptor, the default STDIN, because you did not specify any; since you attached STDOUT from «find» command to STDIN with a pipe, it works exactly like you explained; what kind of ideas you are asking about?
What i was tryinbg to do was to process the output from the find command query as it is generated and get a user to choose to archive, delete or skip any actions on the large file. I did not want to put the output from the find into an array nor file then process the array/file, Has this would give a period of time where there is no activity on screen whilw the output from the command was collected.
So is there any way round this issue with read using stdin channel for the both reads?
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150
Rep:
No probs, but if you are going to be doing any bash scripting you will want to grab a copy of the advanced bash scripting guide here: http://www.tldp.org/guides.html
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.