> Hi Benjamin, Yes. My script is using osascript to invoke AppleScript. The
> bash script itself is being executed from the macOS Desktop with a
> double-click because it is using the ".command" extension. In the case of
> my temporary filename, it is called utf.command so even if I did write it
> in awk, I doubt very much that Apple provides such a way to double-click
> an awk script.
Apple has provided a facility that allows you to double-click *any* kind of
script. By changing the first line of the script (the "shebang line") from
something like "#!/bin/bash" to something like "#!/usr/bin/awk -f", you can
tell the OS that it should use Awk instead of Bash to run the file. (Shebang
lines have been used in this way for decades in Unix and its derivatives.)
So while I certainly understand that you don't want to rewrite a large,
mostly-working Bash script in another language, the lack of OS support
doesn't seem like it's an issue here :-)
> In any case, there is a reason that the script is bailing after the first
> element of the array is processed and that's all I need to know to solve
> this problem. There seems to be no sense as to why it would bail after
> the first element of the array because the code is very simple in reality.
I'd recommend that you post a minimal example that demonstrates the problem:
a full shell script that can be run as-is, an example data file, and an
explanation of what the output is supposed to look like. Without these
things, it's going to be very difficult for anyone else to debug your
problem.
One very general piece of advice is that in Bash scripts, you almost always
want to double-quote variables and command substitutions unless you
specifically want the shell to split them for you. So, for example, use
"$foo" instead of $foo and "$(example arg1)" instead of $(example arg1).
Another piece of advice is that the built-in "column" utility may be able to
do some of these formatting tasks for you. For example,
$ cat example_file
100001
100002
100003
100004
100005
100006
100007
100008
100009
100010
100011
100012
100013
100014
100015
100016
100017
100018
100019
100020
$ column -x example_file
100001 100002 100003 100004 100005 100006
100007 100008 100009 100010 100011 100012
100013 100014 100015 100016 100017 100018
100019 100020
Hope this helps,
Benjamin