相关疑难解决方法(0)

如果同一个 shell 启动了多个连接,则后台运行的 SSH 连接不会退出

显然,如果同一个 shell 启动到同一个服务器的多个 ssh 连接,它们在执行给定的命令后不会返回,但会永远挂起 ( Stopped (tty input))。为了显示:

#!/bin/bash
ssh localhost sleep 2
echo "$$ DONE!"
Run Code Online (Sandbox Code Playgroud)

如果我在后台多次运行上面的脚本,它永远不会退出:

$ for i in {1..3}; do foo.sh & done
[1] 28695
[2] 28696
[3] 28697
$                      ## Hit enter

[1]   Stopped                 foo.sh

[2]-  Stopped                 foo.sh

[3]+  Stopped                 foo.sh
$                      ## Hit enter again        
$ jobs -l
[1]  28695 Stopped (tty input)     foo.sh
[2]- 28696 Stopped (tty input)     foo.sh
[3]+ 28697 Stopped (tty input)     foo.sh
Run Code Online (Sandbox Code Playgroud)

细节

  • 我发现这个是因为我在 Perl 脚本中 ssh'ing 来运行命令。使用 Perl …

shell ssh terminal stdin

9
推荐指数
1
解决办法
2386
查看次数

Bash:如何跳过卡住的功能?

#!/bin/bash

function thous {
    numfmt --g $1 | sed 's/,/./g;s/@//g'
}

aa="1,235"
bb="5,22"
cc=$(echo "$aa + $bb" | bc)

#1
echo $aa
#2
echo $bb
#3
echo $(thous "$cc")
#4
echo "SKIP"

exit
Run Code Online (Sandbox Code Playgroud)

显示了什么

(standard_in) 1: parse error
(standard_in) 1: parse error
1,235
5,22
Run Code Online (Sandbox Code Playgroud)

我想要的是

(standard_in) 1: parse error
(standard_in) 1: parse error
1,235
5,22
(some error or nothing at all)
SKIP
Run Code Online (Sandbox Code Playgroud)

如果您尝试编译此 bash shell 代码,您将陷入#3。那么,如何告诉终端忽略无法处理的内容并继续下一个过程呢?

如果问题不清楚,请告诉我,谢谢

bash shell-script

4
推荐指数
1
解决办法
945
查看次数

标签 统计

bash ×1

shell ×1

shell-script ×1

ssh ×1

stdin ×1

terminal ×1