In a POSIX shell script, I have a variable that I append to in a loop to create a list. If a condition is met in the loop the variable is appended as follows:
strVar=${strVar}\ $strOwner\,
When the loop completes, an example of the value of strVar is: BVR, HRS,
After the loop completes, I want the results echoed in a log. I want the echo to appear as follows:
*** Review log for problems in BVR, HRS. ***
The following is an example of what I have tried:
echo "\n*** Review log for problems in " \
echo $strVar | awk '{ print substr($0,1,length($0)-1) }' >> $script_log_path
This produces: *** Review log for problems in BVR, HRS
This is almost what I want. I have tried every possible way of coding this to get the ending ". ***" without success.
What I really wanted to do was to reformat strVar after the loop to simply truncate the trailing ", " (comma space) from the string. Then use the resulting strVar in my echo. I thought I could do that using some form of substr (like I did with awk).
I would be satisfied with the above method if I could figure out how to append the remaining ". ***".
I am totally open to a complete recode using any other method.
Can anyone help me out?
strVar=${strVar}\ $strOwner\,
When the loop completes, an example of the value of strVar is: BVR, HRS,
After the loop completes, I want the results echoed in a log. I want the echo to appear as follows:
*** Review log for problems in BVR, HRS. ***
The following is an example of what I have tried:
echo "\n*** Review log for problems in " \
echo $strVar | awk '{ print substr($0,1,length($0)-1) }' >> $script_log_path
This produces: *** Review log for problems in BVR, HRS
This is almost what I want. I have tried every possible way of coding this to get the ending ". ***" without success.
What I really wanted to do was to reformat strVar after the loop to simply truncate the trailing ", " (comma space) from the string. Then use the resulting strVar in my echo. I thought I could do that using some form of substr (like I did with awk).
I would be satisfied with the above method if I could figure out how to append the remaining ". ***".
I am totally open to a complete recode using any other method.
Can anyone help me out?