如何确定Bash脚本被中断的位置?
我的代码
trap stop exit
stop()
{
echo "Script error"
echo "File name: ?"
echo "Line num : ?"
}
r1 . /tmp/1 || exit 1
r2 . /tmp/2 || exit 1
..
..
r3541 . /tmp/3541 || exit 1
r3542 . /tmp/3542 || exit 1
答案 0 :(得分:1)
试试这个:
#!/bin/bash
trap stop exit
stop()
{
echo "Script error"
echo "File name: $0"
echo "Line num : $l"
}
r1 . /tmp/1 || { l=$LINENO; exit 1; }
r2 . /tmp/2 || { l=$LINENO; exit 1; }
..
..
r3541 . /tmp/3541 || { l=$LINENO; exit 1; }
r3542 . /tmp/3542 || { l=$LINENO; exit 1; }