Eu tenho o seguinte código
arrFiles[0]=0
cd "/home/thenok/Documents/Link to thought diary"
for i in $(find -type f ! -name "*~"); do
arrFiles[0]=$[arrFiles[0]+1]
arrFiles[arrFiles[0]]="$i"
echo " pos ${arrFiles[0]} file ${arrFiles[arrFiles[0]]}"
done
mas gera (13 e 23 são arquivos)
pos 354 file ./Link
pos 355 file to
pos 356 file diary/201504/quint/13
pos 357 file ./Link
pos 358 file to
pos 359 file diary/201511/23
o que é ruim porque ao usar outro comando (stat) ao invés de echo ele me dá
stat: cannot stat ‘./Link’: No such file or directory
stat: cannot stat ‘to’: No such file or directory
stat: cannot stat ‘thought’: No such file or directory
stat: cannot stat ‘diary/201411/done/31’: No such file or directory
Eu tentei:
1: usando um caminho direto em vez de um link, 2:
arrFiles[0]=0
FILES="/home/thenok/Documents/Link to thought diary/*"
for i in "$FILES"; do
arrFiles[0]=$[arrFiles[0]+1]
arrFiles[arrFiles[0]]="$i"
echo " pos ${arrFiles[0]} file ${arrFiles[arrFiles[0]]}"
done
#result is pos 1 file /home/thenok/Documents/Link to thought diary/*
3: fazer o array diretamente não usa subpastas
arrFiles=( "/home/thenok/Documents/Link to thought diary/"* )
for f in "${arrFiles[@]}"
do
stat -c %s "$f"
echo "$f"
done
Solução encontrada em Como ler a linha completa em 'for' loop com espaços que é exatamente o que eu queria em primeiro lugar, mas não sabia como escrever no google
IFS=$'\n' # make newlines the only separator
arrFiles[0]=0
cd "/home/thenok/Documents/Link to thought diary"
for i in $(find "/home/thenok/Documents/Link to thought diary/" -type f ! -name "*~"); do
arrFiles[0]=$[arrFiles[0]+1]
arrFiles[arrFiles[0]]="$i"
echo " pos ${arrFiles[0]} file ${arrFiles[arrFiles[0]]}"
done
saída é
pos 10 file /home/thenok/Documents/Link to thought diary/Link to diary/201408/methinks questions.txt
pos 11 file /home/thenok/Documents/Link to thought diary/Link to diary/201408/methinks small.txt
pos 12 file /home/thenok/Documents/Link to thought diary/Link to diary/201408/methinks2.txt
pos 13 file /home/thenok/Documents/Link to thought diary/Link to diary/201408/methinkss.txt
pos 14 file /home/thenok/Documents/Link to thought diary/Link to diary/201408/myfile.txt
pos 15 file /home/thenok/Documents/Link to thought diary/Link to diary/201408/new 2.txt