On Mon, Jun 19, 2023 at 4:22 AM Kerin Millar <kfm@plushkava.net> wrote:
>
> On Mon, 19 Jun 2023 03:37:24 +0900
> Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> > Hi.
> >
> > I'd like to know the proper handling of an environment variable
> > when the value may contain spaces (with quoting).
> >
> > Here is my question.
> >
> > You have the environment variable 'CC', which contains a compiler path.
> >
> > For example, how to write a shell script to
> > compile a C file with ${CC}?
>
> By shell script, do you mean that POSX sh is the intended target?
Thanks for the pointers, all guys.
Ideally, working on POSIX sh would be nice.
So, what I learnt from the link David referenced
and hints from Alex,
[1] With bash extension:
#!/usr/bin/bash
declare -a "cc_command=( ${CC} )"
"${cc_command[@]}" foo.c
"${cc_command[@]}" bar.c
"${cc_command[@]}" baz.c
[2] With POSIX sh
#!/bin/sh
eval set -- "${CC}"
"$@" foo.c
"$@" bar.c
"$@" baz.c
Of course, the latter cannot preserve
the original positional parameters, though.
--
Best Regards
Masahiro Yamada