Re: adding a shell function

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

 



Eric Sunshine <sunshine@xxxxxxxxxxxxxx> writes:

> (4) m4 strips away [ and ] characters as part of its normal processing, so  
> you need to account for this in your 'sed' expression, as illustrated above  
> with [[ and ]].

It might be better to use @<:@ and @:>@ for this (*note
(autoconf)Quadrigraphs::).

> For especially simple functions like yours, you can often easily define m4  
> macros which get the job done just as well, without worrying about  
> portability problems involved with shell functions.  For instance, you can  
> define an m4 macro ADD_TRAILING_SLASH which performs the same job as your  
> shell function, and you can use it in the same way from configure.ac.  For  
> instance:
>
> # aclocal.m4
> AC_DEFUN([ADD_TRAILING_SLASH],
> [{ case $1 in
>   */) echo "$1" ;;
>   *) echo "$1/" ;;
> esac }
> ])
>
> # configure.ac
> AC_INIT(...)
> HAHA=`ADD_TRAILING_SLASH([$somevar])`
> AC_SUBST([HAHA])
> AC_OUTPUT
>
> Note that, in this case, the $1 is an argument of the m4 macro, and is  
> expanded by m4.  The $1 is not intended for the shell.

In which case you have to watch out for proper shell quoting, since the $1
in "case $1 in" may be replaced by a literal that includes meta
characters.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@xxxxxxx
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux