這是這篇文章的后續內容。有人告訴我如何使用 DEBUG 陷阱在每一行之前運行命令,我制作了在陷阱中執行的函式。但是,當從函式中回顯 $LINENO 時,它會回顯文字行號。我需要運行該函式的行號。我該怎么做?
更多解釋,假設一個函式foo在第 25 行定義并在第 100 行運行。在第 26 行foo有命令echo "$LINENO"。我希望它回顯 100(其中該函式foo正在運行)。
而且我很確定您不需要我的代碼,因為我只需要幫助來獲取正在執行該函式的行號。但是,對于出于某種原因絕對需要查看我的代碼的人:您可能在我的代碼中找不到任何有用的東西。
getnextp() {
i=0
small=$1
execute=
while :; do
((i ))
if [ "$i" -gt "$(sed -n '$=' plist)"]; then
break
fi
line=$(sed $i'!d' plist)
if [ "$line" == "$0" ]; then
((i ))
((i ))
line=$(sed $i'!d' plist)
if [ "$line" -lt "$small" ]; then
small="$line"
((i--))
line=$(sed $i'!d' plist)
execute=$line
((i ))
fi
fi
done
}
npl=999999999
step() {
echo "Working."
echo $LINENO
if [ "$(cat plist)" == *"$0"* ]; then
getnextp $1
if [ "$LINENO" == "$small" ]; then
cd ../
./packages/$execute
fi
fi
}
trap "step $npl" DEBUG
uj5u.com熱心網友回復:
在 bash 中,陣列變數 BASH_LINENO 存盤跟蹤。例如:
#!/bin/bash
foo() {
echo at $LINENO in foo, called from ${BASH_LINENO[0]}
echo which was called from line ${BASH_LINENO[1]};
}
bar() { foo; }
bar
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512827.html
標籤:重击壳
