[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Yet another shell function prerequisite!
From: |
Paolo Bonzini |
Subject: |
Re: [PATCH] Yet another shell function prerequisite! |
Date: |
Tue, 14 Oct 2008 06:36:19 +0200 |
User-agent: |
Thunderbird 2.0.0.17 (Macintosh/20080914) |
Ralf Wildenhues wrote:
> * Paolo Bonzini wrote on Mon, Oct 13, 2008 at 07:24:10PM CEST:
>> I'd okay with -, but what if unset does not work? I planned to do
>> something like
>>
>> as_lineno=; AS_UNSET([as_lineno])
>>
>> but that could expand to
>>
>> as_lineno=; false as_lineno
>>
>> Do we still care about "old BSD shells, including the Ultrix sh"? How
>> old are these?
>
> Let's go with unset. IIRC unset is more portable than ${var:-default}
> (and IIRC, where the latter doesn't work, it causes the shell to abort
> the script). Having line number information fail if both are borked is
> tough luck.
In the meanwhile I thought about
as_lineno=${as_lineno-$LINENO} func
which is a slick trick, as it supports nesting and does not require
unset. :-)
I'll commit the attached testcase together with the patch at the top of
the thread:
2008-10-14 Paolo Bonzini <address@hidden>
* tests/m4sh.at (Function pseudo-local variables): New test.
diff --git a/tests/m4sh.at b/tests/m4sh.at
index e7ea7aa..3183932 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -475,6 +475,34 @@ AT_CHECK([./script])
AT_CLEANUP
+## ------------------------ ##
+## Pseudo-local variables. ##
+## ------------------------ ##
+
+AT_SETUP([Function pseudo-local variables])
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+AS_REQUIRE_SHELL_FN([func_var], [var=$var${a-B}])
+
+func_var
+a=b func_var
+func_var
+b=c
+a=${a-$b} func_var
+func_var
+if test $var != BbBcB; then
+ AS_ERROR([func_var test failed])
+fi
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP
+
+
## ------------------------------------ ##
## AS_REQUIRE_SHELL_FN and m4_require. ##
## ------------------------------------ ##
- [PATCH] Yet another shell function prerequisite!, Paolo Bonzini, 2008/10/13
- Re: [PATCH] Yet another shell function prerequisite!, Eric Blake, 2008/10/13
- Re: [PATCH] Yet another shell function prerequisite!, Eric Blake, 2008/10/13
- Re: [PATCH] Yet another shell function prerequisite!, Paolo Bonzini, 2008/10/13
- Re: [PATCH] Yet another shell function prerequisite!, Paolo Bonzini, 2008/10/13
- Re: [PATCH] Yet another shell function prerequisite!, Ralf Wildenhues, 2008/10/13
- Re: [PATCH] Yet another shell function prerequisite!,
Paolo Bonzini <=
- Re: [PATCH] Yet another shell function prerequisite!, Paolo Bonzini, 2008/10/14
- Re: [PATCH] Yet another shell function prerequisite!, Eric Blake, 2008/10/14
- Re: [PATCH] Yet another shell function prerequisite!, Eric Blake, 2008/10/14
- Re: [PATCH] Yet another shell function prerequisite!, Eric Blake, 2008/10/14