Je rencontre le problème suivant, avec le script ci dessous :
- /opt/product/arsystem/test/LicenseReport.txt.1298111407
./script.sh: substitution incorrecte
Je souhaite juste récupérer "LicenseReport.txt.1298111407", dans la variable i, et non pas le chemin complet du fichier.
#!/bin/sh
# This would run the loop exactly once, with i="/opt/product/arsystem/test/".
# for i in /opt/product/arsystem/test/
# I think you meant this, to match all files in that dir
for i in /opt/product/arsystem/test/*
do
# just a sanity check. Don't run file on directories.
[ -d "$i" ] && continue
# newline here
file "$i"
echo $i
x=${i##*.}
echo $z
echo $x
echo $t
echo $r
# wrong kind of brackets, and you missed one '
z=${perl -e 'print time'}
# z=$(perl -e 'print time')
r=LicenseReport.txt.$x
t=${echo $z-$x|bc}
if [ "$t" -gt 86400 ];
then
# newline here
tar -cvf $r.tar $r
else
# can't leave a branch empty.
# Use : whenever you need to do nothing.
:
fi
done
Partager