0

I have a bash script my_script which executes:

scp -- 'somehost:*.txt' dest_dir

now, when I run this script from an interactive shell session, scp lists files as it copies them. But when I run a second script, containing:

exec 5>&1
foo=$(my_script | tee /dev/fd/5) || exit -1

(see this question for the motivation) - scp doesn't list the files as it copies them.

Why is that? And can I circumvent this other than by using scp -v?

einpoklum
  • 102,731
  • 48
  • 279
  • 553

1 Answers1

2

Why is that?

scp program checks if output is a tty, and if it is, then it prints progress. If the output is not a tty, then it doesn't print progress information.

And can I circumvent this other than by using scp -v?

How to trick a command into thinking its output is going to a terminal

Specifically, it may be sufficient to prepend the invocation of scp with unbuffer:

unbuffer scp -- 'somehost:*.txt' dest_dir
einpoklum
  • 102,731
  • 48
  • 279
  • 553
KamilCuk
  • 96,430
  • 6
  • 33
  • 74