You are not logged in.
I'm working on a PKGBUILD parser right now to convert the current PKGBUILD format to the current working draft here.
The converter is written in Bash and I'm sourcing the PKGBUILD to get the variables, which works perfectly. What I'm wondering is if there is any way to get Bash to print out the lines inside of a function, e.g. if the PKGBUILD contains
build() {
line1
line2
line3
}
is there any way to get Bash to print
line1
line2
line3
To rephrase it, once I've sourced a Bash file, is there any way to print the loaded function to a file?
Scraping the file is not a good option because there is no guarantee that the build function of a given PKGBUILD will follow a simple layout. I'd prefer to avoid counting braces with Bash, checking for escaped braces, etc.
I've tried searching for the answer, but the search terms make it difficult to find anything relevant.
Last edited by Xyne (2009-07-31 22:30:37)
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
"type function_name" will give you the source of the function (drop the first line or so).
To get a list of what fucntions were defined, I guess you could do "declare -f" before sourcing the file, then again after, and the new items will be your newly defined functions. I think by default "declare -f" gives you the whole function source, but maybe there's a way to suppress that and get only the function names.
If you know what function you're after, such as build(), it's easier.
EDIT: "declare -F" gives just the function names (well, you have to massage the output a bit).
Last edited by Profjim (2009-07-31 22:12:31)
Offline
You have no idea how ridiculously happy that just made me. A quick response and exactly what I needed. Thank you ( and thanks to whoever implemented that).
*marks as solved and happily walks off to keep coding*
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline