加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – “${x %% *}”在sh中意味着什么?

发布时间:2020-12-15 22:57:12 所属栏目:安全 来源:网络整理
导读:我刚刚在makefile中看到“$${x %% *}”,这意味着sh中的“${x %% *}”. 为什么用这种方式写? https://unix.stackexchange.com/questions/28994/how-can-a-makefile-detect-whether-a-command-is-available-in-the-local-machine determine_sum = sum=; f
我刚刚在makefile中看到“$${x %% *}”,这意味着sh中的“${x %% *}”.
为什么用这种方式写?

https://unix.stackexchange.com/questions/28994/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

另外,如何在Google中搜索${x %% *}?

解决方法

除了$x变量中的第一个单词之外,${x %% *}是删除所有内容的好方法.也就是说,给定文本XXX YYY ZZZ,此语法将删除第一个空格后的所有内容.

一些例子:

$x="aaa abbb"
$echo ${x%% *}
aaa

$x="aaa abbb bccc defasdfs"
$echo ${x%% *}
aaa

它相当于:

$x="aaa abbb bccc defasdfs"
$echo $x | awk '{print $1}'
aaa

为了确保它清楚,让我们有另一个例子:

$x="aaa abbb_bccc_defasdfs"
$echo ${x%%_*}
aaa abbb

我们寻找第一个_字符,我们从那一点开始删除到最后.

要查看更多这些有趣的命令,您可以查看Reference Cards #String Operations.

关于Google问题,是的,这些字符无法通过搜索引擎进行搜索.相反,我会建议你使用SymbolHound.

例如,querying ${x%% *}显示了有价值的结果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读