Quote:
Originally Posted by stepk
I didn't explain myself exactly. json_parse calls a user-provided function - make_label in this case. I want for the user-provided function to get an unmodified IFS. So I need to reset IFS before calling the user's function from within json_parse, don't I?
Code:
json_parse() {
local IFS0=$IFS IFS ... foo=$2
...
IFS=,
...
IFS=$IFS0
$foo
...
}
or is the local scoping not affecting called subs?
Also is it safe to save $IFS and declare it local in a single statement, or should I break it into two lines
Code:
local IFS0=$IFS
local IFS ...
thanks
|
Yes, you want that - since you shouldn't guess a what an external function might expect.
I really must run (car keys in hand) - but . . . .
Here is a (somewhat large) example (in BASH!) of the handling of a lot of those issues:
http://hg.minimodding.com/repos/cats/shacat.hg/
In particular the topmost defines for the IFS strings.
That way a reader will get a clue as to what is happening at each step along the way.