i wonder why i get length 1 returned every time even though $test is empty, even though grep can't find anything.
#!/bin/bash
set -Eeuo pipefail
set -x
declare -a test
test=$(echo "$outputOfOtherCommand" | grep -i '>f\+\+\+\+\+\+\+\+\+' | cut -d' ' -f2) || true
echo "${#test[@]}"
for t in $test
do
echo $t
done
The $outputOfOtherCommand includes the output of Rsync. The test_new_file was only created for clarity.
➜ ~ ./script.sh
.d..t...... ./
>f+++++++++ test_new_file
Number of files: 10 (reg: 9, dir: 1)
Number of created files: 1 (reg: 1)
Number of deleted files: 0
Number of regular files transferred: 1
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 280
Total bytes received: 38
The only thing I can explain is that an empty entry was created at array position 0. But i don't know. Maybe you can help me.
forloop does not make any sense. The loop body will be executed exactly once, withthaving the literal string test.