【问题标题】:linux cp command different behavior between cmd line and shell script.linux cp 命令在 cmd 行和 shell 脚本之间有不同的行为。
【发布时间】:2014-01-13 10:32:18
【问题描述】:

在构建gcc-4.8.1时,遇到了一个cp命令如下:

#!/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

【问题讨论】:

  • 尝试使用bash 而不是sh。我想我以前遇到过这个问题,并且这样做解决了它。
  • 它有效,非常感谢。 sh -> 默认破折号。
  • 确保您在 src 文件夹之外构建。我建议你通读LFS 尤其是gcc 上的部分。
  • 是的。我按照 LFS 7.4 chapt5 的步骤构建了 gcc,并在 src 文件夹之外构建了 mkdir。
  • 如果您更喜欢bash 而不是dash,在Debian 上您可以使用dpkg-reconfigure dash 并将bash 设置为默认shell。在我看来,使用dash 的任何“性能”优势都可以忽略不计。

标签: linux shell


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多