URL: https://linuxfr.org/forums/programmation-shell/posts/recherche-et-incremente-un-numero-au-fichier Title: recherche et incremente un numero au fichier Authors: xusnet Date: 2005年09月27日T17:01:02+02:00 Tags: Score: 0 Bonjour a tous. exécutant un logiciel et en mettant en argument le fichier log. j'ai mis au point un petit script qui permet a chaque exécution. Mon problème est le suivant: je fait un script qui permet d'incrémenter un nombre au nom de mon fichier log qui est en argument. ex: nom du log 001_fichier-200509.txt ---------------------------- #!/bin/ksh set -x # Déclaration Numfic=000 Nomfic="_fichier-" datefic`date '+%Y%m'` ext=".txt" # recherche dans le repertoire dernier fichier existant: rech=`ls -fl | tail -1| cut -c57-` Num=`expr $rech + 1` if [ $rech =! "001"] then ./mon logiciel -C 001$Nomfic$datefic$ext else ./mon logiciel -C $Num$Nomfic$datefic$ext fi -C permet de cree un fichier log ----------------------------- si le fichier 001_fichier-200509.txt n'existe pas, mets en argument 001 si le fichier 001_fichier-200509.txt existe, il prochain en argument sera 002_fichier-200509.txt ainsi de suite. Mais voilà je suis bloqué quand cela passe a +10 jusqu'a 009 ca marche. Comment faire ?