
Soy terrible con las secuencias de comandos bash y necesito ayuda con lo siguiente:
#!/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 {} \;
El problema aquí es la línea ncftpput... si en su lugar hago un simple [ echo "working" ], todo está bien, pero cuando pruebo la línea ncftpput solo me da [línea 5: [: demasiados argumentos]
el comando ncftpput por sí solo funciona bien.
¿Algunas ideas?
Respuesta1
No puede usar globbing con -e
inside []
porque es probable que devuelva más de un resultado, lo que le dará un error de demasiados argumentos.
Puedes probar:
shopt -s nullglob
if [[ -n "$(echo Pretty*)" ]]
o
if [[ "$(echo Pretty*)" != "Pretty*" ]]
Además, utilice sangría, espacios y continuación de línea para que su código sea más legible:
#!/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 {} \;
Respuesta2
Intentalo.
#!/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 {} \;
Respuesta3
Bueno, si se queja de demasiados argumentos, divídelo con un 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 {} \;
El uso de "" alrededor de $FILE garantizará que los archivos con espacios en su nombre no hagan nada inesperado.