I am trying to get a bash array of all the unstaged modifications of files in a directory (using Git). The following code works to print out all the modified files in a directory:
git -C $dir/.. status --porcelain | grep "^.\w" | cut -c 4-
This prints
"Directory Name/File B.txt"
"File A.txt"
I tried using
arr1=($(git status --porcelain | grep "^.\w" | cut -c 4-))
but then
for a in "${arr1[@]}"; do echo "$a"; done
(both with and without the quotes around ${arr1[@]}
prints
"Directory
Name/File
B.txt"
"File
A.txt"
I also tried
git -C $dir/.. status --porcelain | grep "^.\w" | cut -c 4- | readarray arr2
but then
for a in "${arr2[@]}"; do echo "$a"; done
(both with and without the quotes around ${arr2[@]}
) prints nothing. Using declare -a arr2
beforehand does absolutely nothing either.
My question is this: How can I read in these values into an array? (This is being used for my argos plugin gitbar, in case it matters, so you can see all my code).