How do I use a nonstandard file descriptor for reading a file into an array with mapfile?
1
vote
2
answers
238
views
mapfile -t -u 7 arr < textfile
gives me
bash: mapfile: 7: invalid file descriptor: Bad file descriptor
Other, more verbose, methods of reading files line-by-line do allow for such descriptor, e.g.
read_w_while() {
while IFS="" read -u 7 -r l || [[ -n "${l}" ]]; do
echo "${l}"
done 7< textfile
The standard descriptor, 0
, is used quite a lot.
Does using such descriptor make scripting more secure from interference? My experience is that so far I only witnessed, I am a Ubuntu Desktop user, such interference when using while IFS="" read -u 7 ...
with the descriptor 7
. What might be the reasons of such interference.
Asked by John Smith
(827 rep)
Jan 1, 2024, 01:33 PM
Last activity: Jan 1, 2024, 07:37 PM
Last activity: Jan 1, 2024, 07:37 PM