Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

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.

1 Answer

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
2  
Not just bash, specified by POSIX sh. See Parameter Expansion in Shell Command Language. –  manatwork May 7 '13 at 8:34
add comment

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