-1

I was going through some shell scripts, and I came across (for the first time) the use "%", some thing like:

build/audio/base/%.wav: src-audio/%.wav

I do not know what it is supposed to mean. Is it some thing like "*"?

Thanks!

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Y91
  • 43
  • 9
  • what is the context? it may be intended for string substitution would be my first guess. – Clay Nov 21 '15 at 00:04
  • Possible duplicate of [Bash: manipulating with strings (percent sign)](http://stackoverflow.com/questions/16444004/bash-manipulating-with-strings-percent-sign) – TheGrandPackard Nov 21 '15 at 00:04
  • What language and platform are you asking about? Because that doesn't look like bash. – Elliott Frisch Nov 21 '15 at 00:06
  • 2
    That is probably a [`Makefile`](http://www.gnu.org/software/make/manual/make.html#Pattern-Examples). – Kenney Nov 21 '15 at 00:06
  • @Kenney Yes, it is a make file, I was told Makefiles are basically shell scripts.. am I misinformed? – Y91 Nov 21 '15 at 00:09
  • @ClaytonSmith yes, looks like string substitution, but I am not sure, how it works, I can't find anything in the code which would tell it, substitute % by "xyz" – Y91 Nov 21 '15 at 00:11
  • @ElliottFrisch, hmm, it is a Makefile, aren't they actually shell scripts? – Y91 Nov 21 '15 at 00:11
  • 1
    A makefile is not anything like a shell script. – Ignacio Vazquez-Abrams Nov 21 '15 at 00:12
  • A shell script is too vague of a term on UNIX/Linux, because there's many kinds of shells. Most shell scripts you'll find are bash scripts, and they have something like `#!/bin/bash` or `#!/bin/sh` as their first line. It can also be `#!/usr/bin/perl`, in which case it is a perl script (which is not a shell), etc.. – Kenney Nov 21 '15 at 00:13

1 Answers1

2

That is from a makefile, not a shell script. From the documentation:

A target pattern is composed of a ‘%’ between a prefix and a suffix, either or both of which may be empty. The pattern matches a file name only if the file name starts with the prefix and ends with the suffix, without overlap. The text between the prefix and the suffix is called the stem. Thus, when the pattern ‘%.o’ matches the file name test.o, the stem is ‘test’. The pattern rule prerequisites are turned into actual file names by substituting the stem for the character ‘%’. Thus, if in the same example one of the prerequisites is written as ‘%.c’, it expands to ‘test.c’.

So every file that matches "build/audio/base/*.wav" has a dependency of "src-audio/*.wav" where the two parts that are represented by "*" must match.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Yes, it is a makefile, while I am at it, can you also tell me what does ":" mean here? you mentioned something about dependency. can you elaborate? Thanks! – Y91 Nov 21 '15 at 00:20