问题描述
我试图找到一种方法来找出哪些文件和行号的函数从调用。该功能在目前正由我的脚本源库文件。
文件1:
$源文件2
$ warn_me错误:你没有做什么
文件2:
$函数warn_me(){
$消息= ????
$回声$ {}消息
$}
所需的输出: $:文件1:2号线:错误:你没有做什么的
函数调用,所以我试图找到一种方式来做到这一点不改变已经发生在许多文件多次。
previously的warn_me函数在使用它的每一个文件中定义,这是照顾,像这样:
$本地消息=$ BASH_SOURCE :($ {} BASH_LINENO):$ *
您正在寻找它似乎。
$猫h.sh
#! /斌/庆典
功能warn_me(){
回声$ @
呼叫者
}
$猫g.sh
#!/斌/庆典
来源h.sh
warn_me错误:你没有做什么
$。 g.sh
错误:你没有做什么
3 g.sh
I'm trying to find a way to find out what file and line number a function was called from. The function is in a library file which is being sourced by my script.
file1:
$source file2
$warn_me "Error: You didn't do something"
file2:
$function warn_me() {
$ message=????
$ echo ${message}
$}
Desired Output: $: file1:Line 2: Error: You didn't do something
The function call already occurs many times in many files so I'm trying to find a way to do this without changing that.
Previously the warn_me function was defined in every file that used it and this was taken care of like so:
$local message="$BASH_SOURCE:(""${BASH_LINENO}): ""$*"
You are looking for caller
it seems.
$ cat h.sh
#! /bin/bash
function warn_me() {
echo "$@"
caller
}
$ cat g.sh
#!/bin/bash
source h.sh
warn_me "Error: You didn't do something"
$ . g.sh
Error: You didn't do something
3 g.sh
这篇关于击:从采购文件中的函数调用的查找线路号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!