Bonjour
Frédéric Mantegazza a écrit :
> Bonjour,
>
> Est-ce que quelqu'un peut m'expliquer les syntaxes suivantes, en shell :
>
> ${1%.*}
olivier@phoenix:~$ TOTO="aaaaaa.bbb" ;echo ${TOTO%.*}
aaa
Cela permet de supprimer l'extension d'un fichier
> et
>
> ${@##*/}
olivier@phoenix:~$ TOTO="aaa/bbbb/cccc" ;echo ${TOTO##*/}
cccc
C'est utiliser pour récupérer le nom d'un fichier, à partir de son
chemin complet
> Je connais $1 et $@, mais que font les {}, % et autres ## ?
man bash :
<extrait>
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in
pathname expansion. If the pattern matches the beginning of the value
of parameter, then the result of the expansion is the expanded value
of parameter with the shortest matching pattern (the “#” case) or the
longest matching pattern (the “##” case) deleted. If parameter is @ or
*, the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list. If
parameter is an array variable subscripted with @ or *, the pattern
removal operation is applied to each member of the array in turn, and
the expansion is the resultant list.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in
pathname expansion. If the pattern matches a trailing portion of the
expanded value of parameter, then the result of the expansion is the
expanded value of parameter with the shortest matching pattern (the “%”
case) or the longest matching pattern (the “%%” case) deleted. If
parameter is @ or *, the pattern removal operation is applied to each
positional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or *, the
pattern removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
</extrait>
Cette page de "man" est particulièrement obscure !!!! ;)
> Merci d'avance.
De rien.
Cordialement
Olivier
--
~~~~~~~ _____/\_____ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phoenix / _ \/ _ \ Olivier Allard-Jacquin
/ / \ / \ \ Web: http://olivieraj.free.fr/
/___/ / \ \___\ Mail: olivieraj@???
~~~~ ///// ///\\\ \\\\\ ~~~~~~~~~~~~~~~~~~~~~~~ Linux Powered !!