09-21-2016
247,
55
Join Date: Jun 2011
Last Activity: 31 January 2020, 9:04 AM EST
Posts: 247
Thanks Given: 40
Thanked 55 Times in 48 Posts
As for displaying the full path, you have two choices: If you know that the file names are always relative pathes, the easiest is to prepend $PWD/. If this is not the case, or if you want to have the path "cleaned up" by not containing .. elements, you need to convert it to an absolute path explicitly. Google for "how to convert a relative path to an absolute path".
Aside from this, the logic of your script is flawed. You obviously want to treat each file separately, i.e. create for each file some information, whether it is missing or not. You have (at least) two choices to achieve this:
The first ist to output the desired information INSIDE the if-block where you detect that the file is missing. The second one - if, for whatever reason, you want to keep problem DETECTION and problem REPORTING separate, I suggest a completely differnt approach:
Either use two arrays (one containing all the file names, and one containing a code for the problem occuring with each corresponding file, for instance "missing" or "ok"), or alternatively use only one associative array, where the key is the file name and the value is "missing" or "ok".
---------- Post updated at 08:58 AM ---------- Previous update was at 08:50 AM ----------
I just noticed - by re-reading your initial post - that you never indicated which shell you are using, so some of the suggestions (such as associative arrays) I gave might not work in your shell.
Hence, the first step would be that you decide on a certain shell language, before we can discuss, how exactly a problem can be solved.
Common language choices are:
- POSIX shell (most unconvenient to program, but maximum compatibility - this is often used by system administrators who have to manage a network of different Unix flavours or different shell versions)
- bash (chances are highest that, if you ask a colleague, s/he will know it)
- Zsh (IMO most convenient for shell programming)
- ksh (Many people like it; I can't comment on it, because of lack of experience)
I use for most of my shell programming Zsh, because it is really made for programmers, but bash is also a very popular choice.