A stupid "while true" loop question
Please excuse my ignorance...I only do what I need and move on.
I've been trying to clear a variable to initiate another go at the process and cannot make it work. I've Frankenstein this below: while true; do read -p "Do you want to scan another file? (y\n) " yn case $yn in [Yy]* ) unset ${TARGET_FILE} ls -h read -p "Enter the name of the file: " file read $file >> ${TARGET_FILE} exec ./runpe ${TARGET_FILE}; break;; [Nn]* ) break;; esac done Basically, I've created a bash script to use various CLI tools to scan files for forensic analysis. This portion above would "allow" me to restart the entire script or at least that's what I need it to do. I have a co-worker that says I have to either wrap the entire code in a while loop or copy and paste the entire thing all over again for the next round of files. This doesnt sound correct to me and he doesnt want to help me out. Thank you all in advance. |
Quote:
Sorry, I did not know that true was a reserved word in Java. |
Code:
while true; do Code:
read $file >> ${TARGET_FILE} Code:
cp $file > ${TARGET_FILE} In addition if you want you can add a default case statement i.e. *) to the end so that just pressing the Enter key will loop without having to enter Y each time. |
As michaelk said, you haven't explained clearly what is going wrong, but I guess the main problem is here:
Quote:
|
I am with the others above in that the issue appears to be you have put too much in to the script.
If I have understood the issue, you need the following 3 things removed: 1. the "break" in the 'Y' section is not required as this will break the infinite loop and hence your script will only run once 2. the "file" variable and replace it with TARGET_FILE 3. the exec, as above this is not required to run the program you have listed So the new copy would be: Code:
while true; do |
unset $TARGET_FILE
does not make sense, you certainly want unset TARGET_FILE and you can omit it, because you redefine TARGET_FILE anyway. |
Quote:
Code:
$ type true |
thank you all for your replies. Thanks to Grail and MadeInGermany...it did help and its doing what I wanted it to do. Thanks for the lesson!!!
|
All times are GMT -5. The time now is 03:16 AM. |