【问题标题】:scp doesn't list then when run in subshell scriptscp 在 subshel​​l 脚本中运行时没有列出
【发布时间】:2021-12-11 15:56:02
【问题描述】:

我有一个 bash 脚本 my_script 执行:

scp -- 'somehost:*.txt' dest_dir

现在,当我从交互式 shell 会话运行此脚本时,scp 会在复制文件时列出文件。但是当我运行第二个脚本时,包含:

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

(有关动机,请参阅 this question)- scp 在复制文件时不会列出文件。

这是为什么呢?除了使用scp -v,我还能绕过这个吗?

【问题讨论】:

  • 它可能使用stderror来输出文件列表
  • @Ivan:不,请参阅 Kamilcuk 的回答。

标签: bash scp subshell verbose verbosity


【解决方案1】:

这是为什么呢?

scp program checks 如果输出是 tty,如果是,则打印进度。如果输出不是 tty,则不会打印进度信息。

除了使用 scp -v 之外,我还能绕过这个吗?

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

具体来说,在调用scp 之前加上unbuffer 可能就足够了:

unbuffer scp -- 'somehost:*.txt' dest_dir

【讨论】:

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