Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I just saw "$${x%% *}" in a makefile, which means "${x%% *}" in sh. Why it is written in this way ?

how can a makefile detect whether a command is available in the local machine?

determine_sum = \
        sum=; \
        for x in sha1sum sha1 shasum 'openssl dgst -sha1'; do \
          if type "$${x%% *}" >/dev/null 2>/dev/null; then sum=$$x; break; fi; \
        done; \
        if [ -z "$$sum" ]; then echo 1>&2 "Unable to find a SHA1 utility"; exit 2; fi

checksums.dat: FORCE
    $(determine_sum); \
    $$sum *.org
share|improve this question

marked as duplicate by jasonwryan, manatwork, vonbrand, Renan, Mat May 7 '13 at 13:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 5 down vote accepted

It's a POSIX shell variable substitution feature :

${var%Pattern} Remove from $var the shortest part of $Pattern that matches the back end of $var.
${var%%Pattern} Remove from $var the longest part of $Pattern that matches the back end of $var.

So if var="abc def ghi jkl"

echo "${var% *}" # will echo "abc def ghi"
echo "${var%% *}" # will echo "abc"
share|improve this answer
Not just bash, specified by POSIX sh. See Parameter Expansion in Shell Command Language. – manatwork May 7 '13 at 8:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.