请教$(cat test.txt)的意思和用法?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
azazazaz
帖子: 37
注册时间: 2008-11-28 13:29

请教$(cat test.txt)的意思和用法?

#1

帖子 azazazaz » 2012-09-05 14:30

有个命令:
printf '%s\t %s\t %s\t %s\t %s\t \n' $(cat test.txt)
最后的$(cat test.txt)是什么意思?

$(命令),有这样的用法吗?
头像
lxr1234
帖子: 721
注册时间: 2009-04-10 11:15
来自: 三民主义国国民权利省我的选择市中共下台镇

Re: 请教$(cat test.txt)的意思和用法?

#2

帖子 lxr1234 » 2012-09-05 14:41

没错,就是执行这个命令,不然中间的空格成了分割符
强烈反对M$的ARM Secure Boot 锁定要求,大家请签名反对
http://www.fsf.org/campaigns/secure-boo ... cted-boot/
头像
azazazaz
帖子: 37
注册时间: 2008-11-28 13:29

Re: 请教$(cat test.txt)的意思和用法?

#3

帖子 azazazaz » 2012-09-05 14:46

$(命令)这是什么用法?有详细点的说明吗?
514617335
帖子: 21
注册时间: 2010-07-09 17:12

Re: 请教$(cat test.txt)的意思和用法?

#4

帖子 514617335 » 2012-09-05 17:21

就是把这条命令的执行结果放在这里。跟``有点像,不过``会在整条语句执行前先执行,而$()会到这个地方的时候再执行。
头像
azazazaz
帖子: 37
注册时间: 2008-11-28 13:29

Re: 请教$(cat test.txt)的意思和用法?

#5

帖子 azazazaz » 2012-09-06 0:27

明白了,多谢上面两位朋友。
头像
naturalaw
帖子: 1360
注册时间: 2011-09-06 22:04

Re: 请教$(cat test.txt)的意思和用法?

#6

帖子 naturalaw » 2012-09-06 8:20

514617335 写了:就是把这条命令的执行结果放在这里。跟``有点像,不过``会在整条语句执行前先执行,而$()会到这个地方的时候再执行。
``和$()的差异在于转义和可移植性,而不是引用中所说的。
``在多层使用时,要使用转义;$()无需。``的移植性较$()好。
参考shell 13问。
  • The eternal law
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: 请教$(cat test.txt)的意思和用法?

#7

帖子 tusooa » 2012-09-08 11:37

代码: 全选

   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.

代码: 全选

] ls -ld //
头像
13378333
帖子: 322
注册时间: 2012-05-31 12:00

Re: 请教$(cat test.txt)的意思和用法?

#8

帖子 13378333 » 2012-09-11 13:40

lxr1234 写了:没错,就是执行这个命令,不然中间的空格成了分割符
%s 是神马意思?
回复