我正在运行以下脚本,其中for循环中的glob扩展为非常大的文件集。出于某种原因,由于按键的退出拒绝采取...脚本打印"检测到按键,退出"但只是继续前进。
我怀疑是否有某些子弹被催生了,它们正在吸收退出电话,但我很难知道如何修复它。该脚本根本不会退出。
#!/bin/sh -e
bindir=`dirname $0`
shopt -s nullglob
dir="$1"
diecygwin=
for complete in "${dir}"/*#complete; do
if [ ! -z "$diecygwin" ]; then
exit "$diecygwin"
continue
fi
seq=${complete//#complete/}
echo -n "${seq} ... "
rc=0
$bindir/other.sh -d "$seq" || rc=$?
if [ $rc -eq 0 ]; then
echo ok
read -t 0.5 -n 1 -s holder && key="$holder"
if [ ! -z "$key" ]; then
echo detected keypress, exiting
exit 0
diecygwin=0
fi
elif [ $rc -ne 100 ]; then
echo fatal error $rc
exit 1
diecygwin=1
fi
done
答案 0 :(得分:1)
只是抬头,你没有使用 <salesforce.init>
<username>sean32@gmail.com</username>
<password>passwordToken</password>
<loginUrl>https://test.salesforce.com/services/Soap/u/29.0</loginUrl>
<forcelogin/>
</salesforce.init>
,而是使用bash
。 sh
缺少sh
所具有的一些功能。这可能会引起麻烦。将您的shebang更改为bash
或#!/bin/bash
。在某些操作系统/ bin / sh指向/ bin / bash,但这改变了一段时间。有关详情,请阅读Difference between sh and bash
如果孩子不会退出,你可以通过
杀死所有孩子和孙子女 #!/usr/bin/env bash
默认信号(TERM = 15)
kill -- -$PGID
SIGKILL(9)
您可以从同一进程树的任何进程ID(PID)中检索PGID
kill -9 -$PGID
(信号TERM)
kill -- -$(ps -o pgid= $PID | grep -o '[0-9]*')
(信号KILL)
我还通过https://www.shellcheck.net/运行了您的脚本,它返回了以下内容:
kill -9 -$(ps -o pgid= $PID | grep -o '[0-9]*')
修改强>
Line 2:
bindir=`dirname $0`
^-- SC2006: Use $(..) instead of legacy `..`.
^-- SC2086: Double quote to prevent globbing and word splitting.
Line 4:
shopt -s nullglob
^-- SC2039: In POSIX sh, 'shopt' is undefined.
Line 14:
seq=${complete//#complete/}
^-- SC2039: In POSIX sh, string replacement is undefined.
Line 15:
echo -n "${seq} ... "
^-- SC2039: In POSIX sh, echo flags are undefined.
Line 17:
$bindir/other.sh -d "$seq" || rc=$?
^-- SC2086: Double quote to prevent globbing and word splitting.
Line 20:
read -t 0.5 -n 1 -s holder && key="$holder"
^-- SC2162: read without -r will mangle backslashes.
^-- SC2039: In POSIX sh, read -t is undefined.
为什么 if [ ! -z "$diecygwin" ]; then
exit "$diecygwin"
continue
fi
在那里?它什么都不做。脚本将在到达之前终止。
中的
continue
也是如此
diecygwin=0
你确定脚本一直在运行吗?它应该在到达退出时终止。如果它没有通过退出后得到什么输出?