BTW, inasmuch as this is a question about *using* the shell more than it is a question about writing scripts for interpretation by the shell, you might consider [unix.se] or [SuperUser](https://superuser.com/) for similar questions in the future.
– Charles DuffyDec 13 '17 at 20:33