find e zip - unknown predicate
Ho uno script:
Codice:
#!/bin/sh
help_desc()
{
cat << EOF
$(basename $0) - comprime una directory in uno zip aggiungendo la data del file più recente nel nome (mydir/ -> mydir-20100102.zip)
EXAMPLE
$(basename $0) ./mydir/ /path/*
EOF
exit 0
}
if [ $# -lt 1 ]; then
help_desc
exit 1
fi
for DIR in "$@"
do
if [ ! -d "$DIR" ]
then
continue
fi
DIR="${DIR%/}"
LASTFILE=`find "$DIR"/ -type f -printf '%TY%Tm%Td\n' | sort | head -n 1`
zip -y0rqT "$DIR"-$LASTFILE.zip "$DIR"/
STATO=$?
if [ $STATO -eq 0 ]
then
# echo "`basename "${DIR%\}"`-$LASTFILE.zip creato, rimuovo `basename "$DIR"`"
echo "$DIR-$LASTFILE.zip creato, rimuovo $DIR/"
rm -rf -- "$DIR"/
fi
done
Il problema è che se la dir inizia con '-' mi becco:
Citazione:
find: unknown predicate `-Boh/'
zip error: Invalid command arguments (short option 'B' not supported)
Conoscete un metodo per ovviare? Alcune utils supportano '--' per indicare "basta argomenti". C'è un equivalente per zip e find?
Re: find e zip - unknown predicate
Come workaround potresti fare in modo che se il nome della cartella inizia con '-' ci anteponi un '\' per fare l'escape del carattere successivo...tramite grep e sed dovrebbe essere fattibile :look: