You are not logged in.
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
Probably some esoteric reason... might be better to ask on the autoconf mailing list.
Offline
or on freenode: ##workingset channel, s_cube is very proficient in this matter there.
Offline
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
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
"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page
Offline