as_fn_error ()
{
...
$as_echo "$as_me:${as_lineno-$LINENUM}: error: $1" >&$3
...
}
This basically expands to give:
echo "foobar" >&$3
where the $3 parameter contains the stream number for the log file.
The echo command with the redirection causes a syntax error on some shells.
How do I restructure it to enable the redirection to go to the stream
number held in the $3 parameter?
A portable Bourne compatible shell syntax is required here.
Mark.
--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
> I have a function that is being generated by autoconf as follows:
>
> as_fn_error ()
> {
> ...
> $as_echo "$as_me:${as_lineno-$LINENUM}: error: $1" >&$3
> ...
> }
>
> This basically expands to give:
>
> echo "foobar" >&$3
>
> where the $3 parameter contains the stream number for the log file.
>
> The echo command with the redirection causes a syntax error on some shells.
> How do I restructure it to enable the redirection to go to the stream
> number held in the $3 parameter?
>
> A portable Bourne compatible shell syntax is required here.
>
> Mark.
>
You can try:
eval "echo \"foobar\" >&$3"
> echo "foobar" >&$3
>
> where the $3 parameter contains the stream number for the log file.
>
> The echo command with the redirection causes a syntax error on some
> shells.
Which shells, and what is the text of the error?
> How do I restructure it to enable the redirection to go to the stream
> number held in the $3 parameter?
>
> A portable Bourne compatible shell syntax is required here.
I don't know about Bourne compatible, generally it's best to aim for
POSIX compatibility at a minimum. The reference for this syntax is in
the IEEE Std 1003.1-2008 document, the “Redirection” section
<URL:http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07>.
Bear in mind that “portable syntax” may not necessarily address “causes
syntax error in some shells”. Some shells may simply be non-conformant.
--
\ “It is not enough to have a good mind. The main thing is to use |
`\ it well.” —Rene Descartes |
_o__) |
Ben Finney
ash:
Syntax error: Bad fd number
hsh: (I think this one works)
foobar
dash:
dash: Syntax error: Bad fd number
ksh: (pkdsh)
ksh: >& : illegal file descriptor name
posh:
posh: >& : illegal file descriptor name
bash:
bash: $3: ambiguous redirect
> I don't know about Bourne compatible, generally it's best to aim for
> POSIX compatibility at a minimum.
I cannot guarantee that. There are various POSIX standards, and they
add extensions which break compatibility with existing shells.
Portable Bourne Shell Syntax syntax is basically a subset of POSIX, which
works across all exiting Bourne compatible shells.
I have a syntax scanner for this:
ftp://markhobley.yi.org/devtools/checkbashisms/
I think what is happening here is that the shells are tripping up on the >&$3
syntax **before** the substitution to a value is being made.
Examining the autoconf output:
In an empty directory create a configure.ac file as follows:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.64])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
# Checks for programs.
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT
Now run:
autoconf
Using an editor examine the file configure and search for &$
The problematic line appears in the function as_fn_error as follows:
as_fn_error ()
{
as_status=$?; test $as_status -eq 0 && as_status=1
if test "$3"; then
as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
$as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
fi
$as_echo "$as_me: error: $1" >&2
as_fn_exit $as_status
} # as_fn_error
I found this snipped of code elsewhere in the configure file:
# Handling of arguments.
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
*) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
done
Note the number 5. I reckon that is where $3 gets its value of 5 from.