.sh para percorrer as pastas recursivamente

0

Meu caminho de arquivo é /server/2TB_HDD/TV Shows/ (dentro disso eu tenho cerca de 100 shows, cada um com temporadas neles)

O problema que parece estar tendo é o caminho do arquivo. Parte "Programas de TV".

Problema semelhante se eu o executar como um .sh

(sou meio novo nisso)

Qualquer ajuda é muito apreciada. Obrigado

código:

#!/bin/bash
for f in /server/'2TB_HDD'/TV\ Shows/*;
  do
     [ -d $f ] && cd "$f" && echo Entering into $f and installing packages
  done;

bash test.sh :

test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: /server/2TB_HDD/TV: binary operator expected
test.sh: line 4: [: too many arguments
test.sh: line 4: [: too many arguments
    
por David Brown 07.07.2016 / 05:01

1 resposta

3

Cite $f nos colchetes. Acostume-se com o hábito de citar as variáveis.

Em uma nota lateral, pode-se usar uma abordagem alternativa com find , separador nulo e while ... read VAR ; do ...done structure. Aqui está, por exemplo, eu entrando em cada diretório e fazendo pwd em cada.

find /home/xieerqi -maxdepth 1 -type d -print0 | while IFS= read -d $'
find "/server/2TB_HDD/TV Shows/" -maxdepth 1 -type d -print0 | while IFS= read -d $'
find /home/xieerqi -maxdepth 1 -type d -print0 | while IFS= read -d $'
find "/server/2TB_HDD/TV Shows/" -maxdepth 1 -type d -print0 | while IFS= read -d $'%pre%' DIR ; do
cd "$DIR" && printf "\nEntering into %s and installing packages\n " "$DIR"
done
' DIR ; do cd "$DIR" pwd cd .. done
' DIR ; do cd "$DIR" && printf "\nEntering into %s and installing packages\n " "$DIR" done
' DIR ; do cd "$DIR" pwd cd .. done

No seu caso, você poderia fazer algo como

%pre%     
por Sergiy Kolodyazhnyy 07.07.2016 / 05:08