Problema com script bash

Problema com script bash

Sou péssimo com scripts bash e preciso de ajuda com o seguinte:

#!/bin/bash

if [ -e Pretty* ];then
ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 /home/xbmc/TV/Pretty_Little_Liars/ Pretty*
else
echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;

O problema aqui é a linha ncftpput. Se eu apenas fizer um simples [echo "working"], está tudo bem, mas quando tento a linha ncftpput, ela apenas me dá [linha 5: [: muitos argumentos]

o comando ncftpput sozinho funciona bem.

Alguma ideia?

Responder1

Você não pode usar globbing com -einside []porque é provável que retorne mais de um resultado, o que causará um erro de muitos argumentos.

Podes tentar:

shopt -s nullglob
if [[ -n "$(echo Pretty*)" ]]

ou

if [[ "$(echo Pretty*)" != "Pretty*" ]]

Além disso, use recuo, espaços e continuação de linha para tornar seu código mais legível:

#!/bin/bash

shopt -s nullglob
if [[ -n "$(echo Pretty*)" ]]; then
    ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 \
        /home/xbmc/TV/Pretty_Little_Liars/ Pretty*
else
    echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;

Responder2

Tente.

#!/bin/bash -x

if [ -e "Pretty*" ];then
`ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 /home/xbmc/TV/Pretty_Little_Liars/ Pretty*`
else
echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;

Responder3

Bem, se estiver reclamando de muitos argumentos, quebre com um for.

#!/bin/bash

if [ -e Pretty* ];then
   for FILE in Pretty*
   do
       ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 /home/xbmc/TV/Pretty_Little_Liars/ "$FILE"
   done
else
   echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;

Usar "" em torno de $FILE garantirá que os arquivos com espaços no nome não façam nada inesperado.

informação relacionada