I am trying to save the result from find
as arrays.
Here is my code:
#!/bin/bash
echo \"input : \"
read input
echo \"searching file with this
Bash 4.4 introduced a -d
option to readarray
/mapfile
, so this can now be solved with
readarray -d '' array < <(find . -name "$input" -print0)
for a method that works with arbitrary filenames including blanks, newlines, and globbing characters. This requires that your find
supports -print0
, as for example GNU find does.
From the manual (omitting other options):
mapfile [-d delim] [array]
-d
The first character ofdelim
is used to terminate each input line, rather than newline. Ifdelim
is the empty string,mapfile
will terminate a line when it reads a NUL character.
And readarray
is just a synonym of mapfile
.