Append to an array variable from a pipeline command
问题 I am writing a bash function to get all git repositories, but I have met a problem when I want to store all the git repository pathnames to the array patharray . Here is the code: gitrepo() { local opt declare -a patharray locate -b '\.git' | \ while read pathname do pathname="$(dirname ${pathname})" if [[ "${pathname}" != *.* ]]; then # Note: how to add an element to an existing Bash Array patharray=("${patharray[@]}" '\n' "${pathname}") # echo -e ${patharray[@]} fi done echo -e ${patharray[