URL: https://linuxfr.org/forums/programmation-shell/posts/petits-probl%C3%A8mes-pour-un-script Title: Petits problèmes pour un script Authors: Alexandre Date: 2011年02月23日T22:46:26+01:00 Tags: Score: 0 Bonjour, Je me suis fait un petit script pour créer des images HDR sous Gimp. Basiquement, on lui donne des images raw, et il se charge de les convertir en tif, de les aligner et de créer une pile de calques dans un fichier psd. Le résultat est ensuite ouvert dans Gimp. J'ai quelques problèmes encore que je n'arrive pas à régler... 1/ Je ne vois pas comment gérer les espaces dans les noms de fichier. J'ai crée un fichier .desktop pour ouvrir graphiquement les images depuis un explorateur (avec %f comme expliqué [là-bas](http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html)). mais comment discriminer un espace qui sépare deux fichiers d'un espace qui est dans un nom de fichier ? 2/ A la fin du script, je lance Gimp, mais celui-ci se ferme si on ferme le terminal dans lequel s'éxécute le script... j'ai essayé avec '&', nohup, etc. mais je sèche là Comme les experts semblent courir les rues ici, je tente ma chance, je copie/colle le script en dessous :) ```bash #!/bin/bash [snip] # Default values TMPDIR=/tmp # without ending slash PRGM=gimp # External editor (must be able to open psd files) ALIGN=1 BATCH=2 # 1: all images processed interactively, 2: first image only, 3: batch mode HELP=0 KEEPTMP=0 OUTDIR=$TMPDIR # Output directory and tmp directory are the same by default while getopts p:ni:d:hto: option do case $option in p) PRGM=$OPTARG ;; [moultes options] o) OUTDIR=$OPTARG ;; esac done shift $(($OPTIND -1)); IMAGES=$* WRKDIR="$TMPDIR/HDRstack" if [ "$HELP" = 1 ]; then echo " Usage : HDRstack [options] " [snip] echo " -o : Set folder for output file" else # Display some infos at start echo "" [snip] echo "" # Clean up if test -d "$WRKDIR"; then echo "Cleaning temporary folder" rm $WRKDIR/* else echo "Creating temporary folder" mkdir $WRKDIR fi # Image conversion echo "" # All images interactively processed if [ "$BATCH" = 1 ]; then echo "Converting images (interactive image processing)" for img in $IMAGES; do # Converts raw images echo " Processing $(basename $img)..." ufraw $img --out-path="$WRKDIR" --out-type=tif &> /dev/null done # First image only elif [ "$BATCH" = 2 ]; then echo "Converting images (interactive processing for first image)" FIRST=$(echo $IMAGES|cut -d " " -f 1) # Get first image filename IMAGES=$(echo $IMAGES|cut -d " " -f 2-) # Remove first image from list #Process first image echo " Processing $( basename $FIRST )..." ufraw "$FIRST" --out-path="$WRKDIR" --out-type=tif &> /dev/null # Batch process the rest for img in $IMAGES; do echo " Processing $( basename $img )..." ufraw-batch $img --out-path=$WRKDIR --out-type=tif &> /dev/null done # Batch mode only else echo "Converting images (batch processing)" for img in $IMAGES; do echo " Processing $(basename $img)..." ufraw-batch $img --exposure=0 --out-path=$WRKDIR --out-type=tif &> /dev/null done fi # Image alignment if [ "$ALIGN" = 1 ]; then echo "" echo "Building image stack" echo " Aligning images..." align_image_stack -p $WRKDIR/output.pto -a $WRKDIR/aligned_ $WRKDIR/*.tif &> /dev/null echo " Creating output file..." PTtiff2psd -s -o $TMPDIR/output.psd $WRKDIR/aligned_* &> /dev/null else # Alignment turned off echo "Creating output file..." PTtiff2psd -s -o $OUTDIR/output.psd $WRKDIR/aligned_*.tif &> /dev/null fi # Temp files clean up if [ $KEEPTMP = 0]; then echo "" echo "Cleaning up tmp folder" rm -r $WRKDIR fi echo "" echo "Done !" echo "" echo "Opening result" $PRGM $OUTDIR/output.psd fi ``` Toute remarque est aussi la bienvenue :) Merci ! (et j'ai fait de mon mieux pour l'anglais /o\)

AltStyle によって変換されたページ (->オリジナル) /