You are not logged in.

#1 2009-11-06 04:19:27

PirateJonno
Forum Fellow
From: New Zealand
Registered: 2009-04-13
Posts: 372

test string equals syntax in configure.ac

Hi all, I recently started a project that uses autoconf, and many examples around the place use the following syntax for string equality tests:

if test "x$str" = "xyes"; then ...

I was wondering why this is used as opposed to

if test "$str" = "yes"; then ...

which seems a bit more elegant and in plain bash seems to work fine (even with empty strings etc). Anyone know the reason why it is usually done the first way and not the second?


"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page

Offline

#2 2009-11-06 05:09:22

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Re: test string equals syntax in configure.ac

Probably some esoteric reason... might be better to ask on the autoconf mailing list.

Offline

#3 2009-11-06 21:37:07

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: test string equals syntax in configure.ac

or on freenode: ##workingset channel, s_cube is very proficient in this matter there.

Offline

#4 2009-11-06 21:41:27

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: test string equals syntax in configure.ac

but autoconf was made for POSIX sh (not sure what that supports exactly), and so many developers try to be overly cautious. I know we are not with the linux-only product.s.
it might also be a holdover from people writing tests without the quotes, like  if x$var = xyes; then ...
if you write without the x and $var is an empty string, you'll get a syntax error

Offline

#5 2009-11-07 01:18:48

PirateJonno
Forum Fellow
From: New Zealand
Registered: 2009-04-13
Posts: 372

Re: test string equals syntax in configure.ac

djszapi wrote:

but autoconf was made for POSIX sh (not sure what that supports exactly), and so many developers try to be overly cautious.

Good enough answer for me. Thanks smile


"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page

Offline

Board footer

Powered by FluxBB