Here I am presenting my solution.
I refer to items in the very usefull arcticle
cant-pipe-in-bashs-mapfile-but-why
in
superuser: /questions/1348948/
There the main goal is not only to store the filenames in the array, but to store each one line as an alement in the array.
This I have solved for me.
Here I present my current solution.
It is a full-featured script.
the array filled by bash command mapfile, resp. readarray is not lost;
$? of find and of mapfile are printed (of find to STDERR);
bash job control (set -m) does not need to be disabled; thus the script can - without any preparatory work - be run out of "fc";
the problems with the delimiter ascii null are avoided;
Remarks:
The script is in a debugging state:
lines are numbered with the index of the array;
before lines of a new file will begin, filename with complete directory entry is put into an element of the array and is printed;
framed with comment lines;
both, the directory entry and the framing lines have "## " at beginning of line;
thus can easily be parsed and removed;
# +++++
mapfile -t WEarr <<< "$(find /tmp -maxdepth 1 -name "WEx_08*" -exec /usr/bin/printf "#%.0s" {1..70} ; -exec echo "" ; -exec echo -n "## " ; -exec ls -lad --time-style=long-iso {} ; -exec /usr/bin/printf "#%.0s" {1..70} ; -exec echo "" ; -exec cat {} ; ; WE_retcod_find=$?; echo "WE_retcod_find: ~$WE_retcod_find~" >&2)"
WE_retcod_mapfile=$?
echo "WE_retcod_mapfile: $WE_retcod_mapfile~"
WE_noe_WEarr=${#WEarr[@]}
echo "WE_noe_WEarr: ~$WE_noe_WEarr~"
for WE_element in "${WEarr[@]}"; do
echo "WE_element: ~$WE_element~"
done
for ((i=0; $i<$WE_noe_WEarr; i++)); do
echo "i: $i ;; ~${WEarr[$i]}~"
done
-----
-.-
findandmapfilehere at all and not just simplymyarr=(mysqldump*)? This will even work with filennames with spaces and newlines. – BlackJack Aug 15 '18 at 14:43findto apply additional criteria, e.g. only directories, and only those older than D days, so the additional fexibility makes me preferfind. – David Tonhofer Aug 15 '18 at 17:46X=(a b 'c d')creates an array with three elementsa,b, andc d. Bash performs word splitting and globbing on the content between the parenthesis. – BlackJack Aug 15 '18 at 19:38nullgloboption on (shopt -s nullglob) on formyarr=(mysqldump*)to not end up with the array('mysqldump*')in case no files match. – David Tonhofer Aug 16 '18 at 08:52