分页: 1 / 1
请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-05 14:30
由 azazazaz
有个命令:
printf '%s\t %s\t %s\t %s\t %s\t \n' $(cat test.txt)
最后的$(cat test.txt)是什么意思?
$(命令),有这样的用法吗?
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-05 14:41
由 lxr1234
没错,就是执行这个命令,不然中间的空格成了分割符
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-05 14:46
由 azazazaz
$(命令)这是什么用法?有详细点的说明吗?
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-05 17:21
由 514617335
就是把这条命令的执行结果放在这里。跟``有点像,不过``会在整条语句执行前先执行,而$()会到这个地方的时候再执行。
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-06 0:27
由 azazazaz
明白了,多谢上面两位朋友。
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-06 8:20
由 naturalaw
514617335 写了:就是把这条命令的执行结果放在这里。跟``有点像,不过``会在整条语句执行前先执行,而$()会到这个地方的时候再执行。
``和$()的差异在于转义和可移植性,而不是引用中所说的。
``在多层使用时,要使用转义;$()无需。``的移植性较$()好。
参考shell 13问。
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-08 11:37
由 tusooa
代码: 全选
Command Substitution
Command substitution allows the output of a command to replace the command
name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the command
substitution with the standard output of the command, with any trailing
newlines deleted. Embedded newlines are not deleted, but they may be
removed during word splitting. The command substitution $(cat file) can be
replaced by the equivalent but faster $(< file).
When the old-style backquote form of substitution is used, backslash
retains its literal meaning except when followed by $, `, or \. The first
backquote not preceded by a backslash terminates the command substitution.
When using the $(command) form, all characters between the parentheses make
up the command; none are treated specially.
Command substitutions may be nested. To nest when using the backquoted
form, escape the inner backquotes with backslashes.
If the substitution appears within double quotes, word splitting and path‐
name expansion are not performed on the results.
Re: 请教$(cat test.txt)的意思和用法?
发表于 : 2012-09-11 13:40
由 13378333
lxr1234 写了:没错,就是执行这个命令,不然中间的空格成了分割符
%s 是神马意思?