ILD

Command Substitution
作者:Yuan Jianpeng 邮箱:yuanjp@hust.edu.cn
发布时间:2018-7-24 站点:Inside Linux Development

命令替换,使用命令的输出替换自己,偶两种形式:

$(command)

或者

`command`


bash在一个subshell执环境之下命令,使用标准输出替换命令。输出结尾的newlines被删除。但是内部的newlines不被删除。


$(cat file)可以使用$(<file)替换,后者更快。


当使用$(command)形式时,括号内的字符组成命令,不会被特殊对待。所以:

kill "$(cat "/var/run/wifipid")"

4个引号,中间的引号是命令的,不和外面的引号匹配,此用法是合法的。


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.