![shの「${x%%*}」とはどういう意味ですか? [コピー]](https://linux33.com/image/44760/sh%E3%81%AE%E3%80%8C%24%7Bx%25%25*%7D%E3%80%8D%E3%81%A8%E3%81%AF%E3%81%A9%E3%81%86%E3%81%84%E3%81%86%E6%84%8F%E5%91%B3%E3%81%A7%E3%81%99%E3%81%8B%EF%BC%9F%20%5B%E3%82%B3%E3%83%94%E3%83%BC%5D.png)
私はmakefileで「$${x%% *}」を見ました。これはshで「${x%% *}」を意味します。なぜこのような記事を書くのですか?
makefileは、ローカルコンピュータでコマンドを使用できるかどうかをどのように検出しますか?
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
答え1
これはPOSIXシェル変数置換関数です:
${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.
したがって、var="abc def ghi jkl"
echo "${var% *}" # will echo "abc def ghi"
echo "${var%% *}" # will echo "abc"