Incarnation P. Lee
Incarnation P. Lee

Reputation: 248

linux cp command different behavior between cmd line and shell script.

When building gcc-4.8.1, I met a cp command as following:

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

It will occurs error when execute this script:

  <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 >

But when type it on cmd line directly, it works well as expected. It is very in comprehensive to me.\n

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

Upvotes: 0

Views: 423

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201537

You need to build gcc with "bash". On Ubuntu derived distributions "/bin/sh" in not linked to "/bin/bash" (but to "/bin/dash"); this is documented in the Ubuntu wiki here. I would suggest using a "ppa" if possible.

Upvotes: 1

Related Questions