linux cp命令cmd行和shell脚本之间的不同行为。

时间:2014-01-13 02:16:54

标签: linux shell

构建gcc-4.8.1时,我遇到了如下命令:

#!/bin/sh
set -x
fname="cp.sh"
cp -v $fname.{,.bk}

执行此脚本时会发生错误:

  <29>pli[1050]@~/workspace/shell*0 > sh cp.sh
  + fname=cp.sh
  + cp -v cp.sh{,.bk}
  cp: missing destination file operand after âcp.sh{,.bk}â
  Try 'cp --help' for more information.
  <30>pli[1051]@~/workspace/shell*0 >

但是当直接在cmd行上键入它时,它可以正常工作。这对我来说非常全面。\ n

  <28>pli[1049]@~/workspace/shell*0 > cp -v cp.sh{,.bk}
  cp.sh -> cp.sh.bk
  <29>pli[1050]@~/workspace/shell*0 > ^C

1 个答案:

答案 0 :(得分:1)

您需要使用“bash”构建gcc。在Ubuntu派生的发行版“/ bin / sh”中没有链接到“/ bin / bash”(但是“/ bin / dash”);这在Ubuntu wiki here中有记录。如果可能,我建议使用“ppa”。