Bonjour,
J'ai une ligne commme ça dans un fichier makefile et je ne comprends pas la syntaxe. Est-ce que quelcun saurait ce que ça signifie (notamment les %)?
A="$${B%/}" ;\
Merci
Bonjour,
J'ai une ligne commme ça dans un fichier makefile et je ne comprends pas la syntaxe. Est-ce que quelcun saurait ce que ça signifie (notamment les %)?
A="$${B%/}" ;\
Merci
Donne les lignes qui vont autour. Ce n'est peut-être pas du make, c'est peut-être simplement un morceau de shell dans ton makefile.
Voilà la target entière. J'ai bien compris ce que ça fait mais j'ai juste un doute sur les %/.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 test_test1: @C="$(ABC)" ; \ for B in $$C; do \ FOLDER="$${B%/}" ;\ test "$${B%%*/}" || continue ;\ [ -f $$FOLDER/makefile ] || continue ;\ (cd $$FOLDER && make all) || exit;\ done
Merci
Donc c'est bien du shell.
${B%/} est la valeur de B, moins le slash à la fin. C'est du shell. D'une manière générale, en shell, ${var%pattern} est la valeur de var, moins la plus courte sous-chaine à la fin de var qui match pattern.
Le $ est doublé parce que l'expression passe d'abord à traver make, qui remplace $$ par un $.
Merci beaucoup, c'est effectivement ça. L'expression "$${B%%*/}" signifie-t-elle qu'il faut enlever un nombre quelconque de / à la fin du mot?
Merci encore
Non, elle supprime tout si $B se termine par un slash. En fait la ligne sert à passer à l'élément suivant si $B ne se termine pas par un slash.
Ces syntaxes sont expliquée dans man bash :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 ${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 pat- tern (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/pattern/string} The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pat- tern against its value is replaced with string. If Ipattern begins with /, all matches of pattern are replaced with string. Normally only the first match is replaced. If pattern begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with %, it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omit- ted. If parameter is @ or *, the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable sub- scripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager