scp doesn't list then when run in subshell script

275 Views Asked by At

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?

1

There are 1 best solutions below

0
KamilCuk On BEST ANSWER

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