Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stdout: User file name input

Im writing a data formating bash script. The script reads the file name which is input by the user in the terminal. Of course, when no file under that name is found in that directory, the program ends with a stderr output. I am now trying to implement a (while) loop which recursively asks for user input until a matching file is found and then goes on to executing my data formating commands. Would appreciate some help 🙂

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am now trying to implement a (while) loop which recursively

I would advice against using recursion for this. Just make a simple loop. It could look like this:

while true; do
    IFS= read -rp 'File: ' file
    if [[ -e $file ]]; then
        break;
    fi
    echo "$file doesn't exist, try again"
done

# work with $file here
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading