help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running case commands with the shell function?


From: David Boyce
Subject: Re: Running case commands with the shell function?
Date: Thu, 14 Sep 2017 05:54:51 -0700

Fourth, you don't really need the case statement any more though you might
still have a cosmetic preference. At one time "case" was necessary with
patterns because "if" didn't handle them, but in the POSIX shell they take
the same pattern constructs so you could say "if [[ $$target =  i386-*- ]];
then ... else ... fi".

Fifth, of course, wrap the logic in a standalone shell script which is
arguably better practice anyway. Certainly easier to read and test.

On Thu, Sep 14, 2017 at 5:04 AM, Paul Smith <address@hidden> wrote:

> On Thu, 2017-09-14 at 13:52 +0200, Sébastien Hinderer wrote:
> > Of course this does not work because the first closing parenthesis is
> > interpreted as ending the call to the shell function.
> >
> > Is there a way to actually achieve this, please?
>
> You have at least three choices:
>
> First, use the matched parenthesis form of case; this is valid POSIX
> shell syntax (and I prefer it even in normal shell scripts as it makes
> editor matching etc. simpler):
>
>   case "$target" in
>       (i386-*-) echo foo ;;
>       (*) ;;
>   esac
>
> Make will count the open/close parens properly.
>
> Or second, you could use the curly-brace form of variable/function
> invocation instead, like:
>
>   ${shell ... }
>
> so make will ignore mismatched parentheses.
>
> Or third, you can assign a variable to the close-paren and use that
> instead:
>
>   CP := )
>
>   $(shell ... *$(CP) ;; ...)
>
> Make always parses to the end of the variable or function first, before
> it tries to expand what's inside.
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]