Answer the question
In order to leave comments, you need to log in
Where do new line characters disappear from the array of elements?
Hello everyone,
I don’t understand where new line characters disappear in the following code:
#!/bin/bash
declare -a dir_array
while IFS= read -r -d $'\0'; do
tmp="${REPLY#./}"
dir_array+="$tmp\n"
done < <(find . -maxdepth 1 ! -path . -type d -print0)
readarray -t sorted < <(for a in "${dir_array[@]}"; do printf "$a"; done | sed '/^*$/d' | sort)
emp="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
printf "${dir_array[*]}"
printf $emp
printf $emp
printf $emp
printf "${sorted[*]}"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question