double square bracket in 'case' in 'configure.ac' i[[3456]]86

Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I am trying to understand the following code snippet.
host_cpu='i386'
case "$host_cpu" in
i[[3456]]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[[3456]]86) to a single bracket as in i[3456]86), 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[[3456]]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?
bash shell autoconf
add a comment |Â
up vote
4
down vote
favorite
I am trying to understand the following code snippet.
host_cpu='i386'
case "$host_cpu" in
i[[3456]]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[[3456]]86) to a single bracket as in i[3456]86), 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[[3456]]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?
bash shell autoconf
2
Looks like a bug. I suggest you submit a pull request. And no, it's not a regular expression; it's pattern matching, which works the same as file globs.
â Wildcard
Oct 4 at 1:56
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I am trying to understand the following code snippet.
host_cpu='i386'
case "$host_cpu" in
i[[3456]]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[[3456]]86) to a single bracket as in i[3456]86), 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[[3456]]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?
bash shell autoconf
I am trying to understand the following code snippet.
host_cpu='i386'
case "$host_cpu" in
i[[3456]]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[[3456]]86) to a single bracket as in i[3456]86), 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[[3456]]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?
bash shell autoconf
bash shell autoconf
edited 10 hours ago
ilkkachu
52.8k679145
52.8k679145
asked Oct 4 at 1:30
supmethods
5426
5426
2
Looks like a bug. I suggest you submit a pull request. And no, it's not a regular expression; it's pattern matching, which works the same as file globs.
â Wildcard
Oct 4 at 1:56
add a comment |Â
2
Looks like a bug. I suggest you submit a pull request. And no, it's not a regular expression; it's pattern matching, which works the same as file globs.
â Wildcard
Oct 4 at 1:56
2
2
Looks like a bug. I suggest you submit a pull request. And no, it's not a regular expression; it's pattern matching, which works the same as file globs.
â Wildcard
Oct 4 at 1:56
Looks like a bug. I suggest you submit a pull request. And no, it's not a regular expression; it's pattern matching, which works the same as file globs.
â Wildcard
Oct 4 at 1:56
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
8
down vote
accepted
If that's a from a configure.ac file, then it's not a pure shell script, but is an Autoconf script using M4, where are quote characters.:
To fully understand where proper quotation is important, you first
need to know what the special characters are in Autoconf: âÂÂ#âÂÂ
introduces a comment inside which no macro expansion is performed,
âÂÂ,â separates arguments, âÂÂ[â and âÂÂ]â are the quotes themselves,
âÂÂ(â and âÂÂ)â (which M4 tries to match by pairs), and finally âÂÂ$âÂÂ
inside a macro definition.
Each time there can be a macro expansion, there is a quotation
expansion, i.e., one level of quotes is stripped:int tab[10];
âÂÂint tab10;
[int tab[10];]
âÂÂint tab[10];
That [[3456]] should be expanded by autoconf to [3456], which would be the correct output for use as a shell script.
1
Indeed - as one can verify by adding a minimalAC_INIT([foo])to the top of the snippet and then executingautoconf snippet
â steeldriver
Oct 4 at 2:27
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
@supmethods you can change the quote characters in M4, and it seems[ ]are set as quote characters in autoconf scripts. The default quote characters in M4 are`', as you have seen.
â muru
Oct 4 at 4:17
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
 |Â
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
If that's a from a configure.ac file, then it's not a pure shell script, but is an Autoconf script using M4, where are quote characters.:
To fully understand where proper quotation is important, you first
need to know what the special characters are in Autoconf: âÂÂ#âÂÂ
introduces a comment inside which no macro expansion is performed,
âÂÂ,â separates arguments, âÂÂ[â and âÂÂ]â are the quotes themselves,
âÂÂ(â and âÂÂ)â (which M4 tries to match by pairs), and finally âÂÂ$âÂÂ
inside a macro definition.
Each time there can be a macro expansion, there is a quotation
expansion, i.e., one level of quotes is stripped:int tab[10];
âÂÂint tab10;
[int tab[10];]
âÂÂint tab[10];
That [[3456]] should be expanded by autoconf to [3456], which would be the correct output for use as a shell script.
1
Indeed - as one can verify by adding a minimalAC_INIT([foo])to the top of the snippet and then executingautoconf snippet
â steeldriver
Oct 4 at 2:27
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
@supmethods you can change the quote characters in M4, and it seems[ ]are set as quote characters in autoconf scripts. The default quote characters in M4 are`', as you have seen.
â muru
Oct 4 at 4:17
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
 |Â
show 2 more comments
up vote
8
down vote
accepted
If that's a from a configure.ac file, then it's not a pure shell script, but is an Autoconf script using M4, where are quote characters.:
To fully understand where proper quotation is important, you first
need to know what the special characters are in Autoconf: âÂÂ#âÂÂ
introduces a comment inside which no macro expansion is performed,
âÂÂ,â separates arguments, âÂÂ[â and âÂÂ]â are the quotes themselves,
âÂÂ(â and âÂÂ)â (which M4 tries to match by pairs), and finally âÂÂ$âÂÂ
inside a macro definition.
Each time there can be a macro expansion, there is a quotation
expansion, i.e., one level of quotes is stripped:int tab[10];
âÂÂint tab10;
[int tab[10];]
âÂÂint tab[10];
That [[3456]] should be expanded by autoconf to [3456], which would be the correct output for use as a shell script.
1
Indeed - as one can verify by adding a minimalAC_INIT([foo])to the top of the snippet and then executingautoconf snippet
â steeldriver
Oct 4 at 2:27
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
@supmethods you can change the quote characters in M4, and it seems[ ]are set as quote characters in autoconf scripts. The default quote characters in M4 are`', as you have seen.
â muru
Oct 4 at 4:17
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
 |Â
show 2 more comments
up vote
8
down vote
accepted
up vote
8
down vote
accepted
If that's a from a configure.ac file, then it's not a pure shell script, but is an Autoconf script using M4, where are quote characters.:
To fully understand where proper quotation is important, you first
need to know what the special characters are in Autoconf: âÂÂ#âÂÂ
introduces a comment inside which no macro expansion is performed,
âÂÂ,â separates arguments, âÂÂ[â and âÂÂ]â are the quotes themselves,
âÂÂ(â and âÂÂ)â (which M4 tries to match by pairs), and finally âÂÂ$âÂÂ
inside a macro definition.
Each time there can be a macro expansion, there is a quotation
expansion, i.e., one level of quotes is stripped:int tab[10];
âÂÂint tab10;
[int tab[10];]
âÂÂint tab[10];
That [[3456]] should be expanded by autoconf to [3456], which would be the correct output for use as a shell script.
If that's a from a configure.ac file, then it's not a pure shell script, but is an Autoconf script using M4, where are quote characters.:
To fully understand where proper quotation is important, you first
need to know what the special characters are in Autoconf: âÂÂ#âÂÂ
introduces a comment inside which no macro expansion is performed,
âÂÂ,â separates arguments, âÂÂ[â and âÂÂ]â are the quotes themselves,
âÂÂ(â and âÂÂ)â (which M4 tries to match by pairs), and finally âÂÂ$âÂÂ
inside a macro definition.
Each time there can be a macro expansion, there is a quotation
expansion, i.e., one level of quotes is stripped:int tab[10];
âÂÂint tab10;
[int tab[10];]
âÂÂint tab[10];
That [[3456]] should be expanded by autoconf to [3456], which would be the correct output for use as a shell script.
answered Oct 4 at 2:16
muru
34k578147
34k578147
1
Indeed - as one can verify by adding a minimalAC_INIT([foo])to the top of the snippet and then executingautoconf snippet
â steeldriver
Oct 4 at 2:27
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
@supmethods you can change the quote characters in M4, and it seems[ ]are set as quote characters in autoconf scripts. The default quote characters in M4 are`', as you have seen.
â muru
Oct 4 at 4:17
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
 |Â
show 2 more comments
1
Indeed - as one can verify by adding a minimalAC_INIT([foo])to the top of the snippet and then executingautoconf snippet
â steeldriver
Oct 4 at 2:27
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
@supmethods you can change the quote characters in M4, and it seems[ ]are set as quote characters in autoconf scripts. The default quote characters in M4 are`', as you have seen.
â muru
Oct 4 at 4:17
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
1
1
Indeed - as one can verify by adding a minimal
AC_INIT([foo]) to the top of the snippet and then executing autoconf snippetâ steeldriver
Oct 4 at 2:27
Indeed - as one can verify by adding a minimal
AC_INIT([foo]) to the top of the snippet and then executing autoconf snippetâ steeldriver
Oct 4 at 2:27
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
Okay, thanks. I've read about m4 and they used the quote characters ` and ' in those articles. So the must have changed the quotes in the configure.ac to treat [ and ] as quotes.
â supmethods
Oct 4 at 3:56
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
The link you provided use [ and ] as quotes. Does this depend on M4 version used?
â supmethods
Oct 4 at 4:01
@supmethods you can change the quote characters in M4, and it seems
[ ] are set as quote characters in autoconf scripts. The default quote characters in M4 are `' , as you have seen.â muru
Oct 4 at 4:17
@supmethods you can change the quote characters in M4, and it seems
[ ] are set as quote characters in autoconf scripts. The default quote characters in M4 are `' , as you have seen.â muru
Oct 4 at 4:17
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
I updated the post and would like to know the main purpose of the case statement. AC_CANONICAL_HOST computes the host_cpu, host_vendor, and host_os. Doesn't it mean that you don't need assignment of the variables (as in host_cpu=i386 and host_cpu=x86_64), and that you can simply do an "if $host_cpu is false then AC_MSG_ERROR([unsupported CPU type])"? host_cpu should already be set from AC_CANONICAL_HOST, so shell variable can be set straight away (AC_SUBST(host_cpu) without the assignment).
â supmethods
11 hours ago
 |Â
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473123%2fdouble-square-bracket-in-case-in-configure-ac-i345686%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Looks like a bug. I suggest you submit a pull request. And no, it's not a regular expression; it's pattern matching, which works the same as file globs.
â Wildcard
Oct 4 at 1:56