double square bracket in 'case' in 'configure.ac' i[[3456]]86
4
votes
1
answer
771
views
I am trying to understand the following code snippet.
host_cpu='i386'
case "$host_cpu" in
i[]86)
echo "host_cpu=i386"
;;
x86_64)
echo "host_cpu=x86_64"
;;
*)
echo "AC_MSG_ERROR([unsupported CPU type]) "
;;
esac
I added the variable
host_cpu='i386'
myself to test the code and it switched to the third case of echo "AC_MSG_ERROR([unsupported CPU type]) "
.
If I change the double bracket in i[]86)
to a single bracket as in i86)
, it switches to the first option yielding i386
. This seems correct to me.
I understand that [
and [[
are the test options. The test condition doesn't seem to apply here as the switch cases are expecting a character to be outputted. So I'm assuming for bash to pick it up as a test condition, it needs to be separated by a space as in [ a < b ]
or [[ a << b ]]
. Because there are no spaces in these case statement, it'll be treated as a regular expression. Is this correct?
So my question is why was the double square bracket was used here by the code writer? It didn't work when I tried to run the code, so what was their intention.
Note: The code was taken from a configure.ac
in the GRUB source code.
Also the $host_cpu and host_cpu=i386 line seem unnecessary, can you explain why the writer would have done this:
AC_CANONICAL_HOST
case "$host_cpu" in
i[]86) host_cpu=i386 ;;
x86_64) host_cpu=x86_64 ;;
*) AC_MSG_ERROR([unsupported CPU type]) ;;
esac
AC_SUBST(host_cpu)
AC_SUBST(host_vendor)
I'm thinking of using AC_SUBST($host_cpu). Why wouldn't you do it this way?
Asked by supmethods
(561 rep)
Oct 4, 2018, 01:30 AM
Last activity: Oct 9, 2018, 01:01 PM
Last activity: Oct 9, 2018, 01:01 PM