Question

While trying to get a better understanding of how the autoconf shell script (/usr/bin/autoconf)works I ran into these couple of lines:

174 if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
175 
176 else
177   exitcode=1; echo positional parameters were not saved.
178 fi

And then later on in the same script:

500 # Run autom4te with expansion.
501 eval set x "$autom4te_options" \
502   --language=autoconf --output=\"\$outfile\" "$traces" \"\$infile\"
503 shift
504 $verbose && $as_echo "$as_me: running $AUTOM4TE $*" >&2
505 exec "$AUTOM4TE" "$@"

"set x" doesn't seem to do anything at all and returns 0 regardless of whether x is defined or not.

Even more confusing are lines 501-502 above which also don't seem to do anything

What am I missing?

Note: Not sure if it makes a difference but posix mode is turned on (set -o posix) earlier in the script)

Était-ce utile?

La solution

This is a rabbit hole down which you do not want to dive! If $autom4te_options is the empty string, then eval set "$autom4te_options" behaves like set with no arguments and prints a bunch of cruft. To protect against that situation, set x $autom4te_options is used instead, which always sets the first positional parameter ($1) to "x". The shift then resets all the positional parameters. Lines 174-178 are probably testing an obscure bug in a dead shell (most auto-tool oddities exist to do that) in which some shell invoked functions but failed to correctly save the positional parameters.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top