Script shell sh ou bash

Bonjour,
je cherche a creer un fichier xml sous cette forme:

<?xml version="" encoding="">
<songs>
<song path="" title="" />
<song path="" title="" />
.....
</songs>

et un repertoire dans le quel sont stocké les musique. voila ce que je voudrai faire:

#!/bin/sh

for i in $(ls rep)
do
#j'ecris dans le fichier un fichier du rep comme ceci :
# <song path="$i" title="{$i%mp3}pseudo" />
done


en gros c ça. c juste une ebauche de ce que je souhaite. je peux le faire en c mais je prefere que ça soit en script shell comme je suis neophite en script shell. merci de vos reponse
Configuration: Windows 7
Firefox 3.5.5

2 réponses

  1. merci pour ton aide j'avais bocou galere a ecrire ça a la main. merci encore
    1. Modérateur
      Salut,

      Un truc du genre :

      [rep]$ ls -1 *mp3     # listing fichier dans /home/jp/tmpfs/rep/
      fichier10.mp3
      fichier1.mp3
      fichier2.mp3
      fichier3.mp3
      fichier4.mp3
      fichier5.mp3
      fichier6.mp3
      fichier7.mp3
      fichier8.mp3
      fichier9.mp3
      [rep]$ cat plop.xml     # contenu fichier xml de départ
      <?xml version="" encoding="">
      <songs>
      </song>
      [rep]$ cat foo.sh     # le script
      #! /bin/sh
      
      #set -xv
      
      for i in $(ls /home/jp/tmpfs/rep/*.mp3)
      do
      NOM=$(basename $i)
      sed -i '$i\
      '"<song path=\"${i}\" title=\"${NOM%mp3}toto\" />"'
      ' plop.xml
      done
      
      [rep]$ ./foo.sh     # l'exécution du script
      [rep]$ cat plop.xml     # le résultat
      <?xml version="" encoding="">
      <songs>
      <song path="/home/jp/tmpfs/rep/fichier10.mp3" title="fichier10.toto" />
      <song path="/home/jp/tmpfs/rep/fichier1.mp3" title="fichier1.toto" />
      <song path="/home/jp/tmpfs/rep/fichier2.mp3" title="fichier2.toto" />
      <song path="/home/jp/tmpfs/rep/fichier3.mp3" title="fichier3.toto" />
      <song path="/home/jp/tmpfs/rep/fichier4.mp3" title="fichier4.toto" />
      <song path="/home/jp/tmpfs/rep/fichier5.mp3" title="fichier5.toto" />
      <song path="/home/jp/tmpfs/rep/fichier6.mp3" title="fichier6.toto" />
      <song path="/home/jp/tmpfs/rep/fichier7.mp3" title="fichier7.toto" />
      <song path="/home/jp/tmpfs/rep/fichier8.mp3" title="fichier8.toto" />
      <song path="/home/jp/tmpfs/rep/fichier9.mp3" title="fichier9.toto" />
      </song>
      [rep]$ 

      ;-))