Trouble with bash read command
Hello,
I've wrote me a script that checks for new configuration files after a Slackware upgrade. In Slackware, updates in /etc come as files ending in ".new", i.e. inittab.new. This is of course to avoid screwing up a working configuration. Now, I've written a script that uses find to locate the .new files. It then checks if the corresponding "old" file exists, and asks me if I want to diff them. Then it asks if I want to move the .new file over the old file. Like this: Code:
#!/bin/sh TIA, Bebo |
The find | while read was queueing up more data then you could read in one read statement. When you attemped to read the y/n, the read was grabbing another filename from the find pipe. Change the find line to this:
Code:
for NEWFILE in `find $DIR -xdev -name '*.new'`; do |
Thanks a lot, crabboy! I would never have realized this myself.
However, I was avoiding the for "method" since I wanted to allow for more general file names, e.g. file names with spaces in them. I think I'm actually gonna solve this by first redirecting the find output to a file, and then look in that file. Again, thanks a lot! :) Cheers |
Set your IFS to be a newline and you can read filenames with spaces.
Code:
IFS=' |
Aha, great, now it actually works :) 'Cause my thought to redirect to a file didn't work either for some reason.
Thanks again :) |
You could use the 'select' command instead of read. This gives you a menu. If you mistype the answer, it will present the options again.
|
All times are GMT -5. The time now is 03:11 PM. |